mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 12:36:40 +00:00
Merge master into breakout_swarm
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
contrib
docker-compose.armhf.ymldocker-compose.ymlgateway
DockerfileGopkg.lockGopkg.toml
handlers
alerthandler.gocreate_handler.godeletehandler.goproxy.goqueueproxy.goreader.goservice_query.goupdate_handler.go
metrics
server.gotests
vendor.confvendor
github.com
Azure
go-ansiterm
Microsoft
go-winio
Nvveen
Sirupsen
logrus
beorn7
perks
docker
cli
LICENSENOTICEREADME.md
opts
env.gohosts.gohosts_unix.gohosts_windows.goip.gomount.goopts.goopts_unix.goopts_windows.goport.goquotedstring.goruntime.gosecret.gothrottledevice.goulimit.goweightdevice.go
vendor.confdistribution
.gitignore.mailmapAUTHORSBUILDING.mdCHANGELOG.mdCONTRIBUTING.mdDockerfilecoverpkg.sh
Godeps
MAINTAINERSMakefileREADME.mdRELEASE-CHECKLIST.mdROADMAP.mdblobs.gocircle.ymlcmd
digest
registry-api-descriptor-template
registry
configuration
context
contrib
apache
compose
docker-integration
DockerfileREADME.mddocker-compose.ymlgolem.confhelpers.bashinstall_certs.sh
malevolent-certs
malevolent.batsnginx
Dockerfiledocker-registry-v2.confnginx.confregistry-basic.confregistry-noauth.confregistry.conftest.passwd
run_multiversion.shtls.batstoken.batsv1
tokenserver-oauth
.htpasswdDockerfile
certs
auth.localregistry.certauth.localregistry.keylocalregistry.certlocalregistry.keysigning.certsigning.key
registry-config-notls.ymlregistry-config.ymltokenserver
token-server
digest
digest.godigest_test.godigester.godigester_resumable_test.godoc.goset.goset_test.goverifiers.goverifiers_test.go
docs
errors.gohealth
manifest
doc.go
manifests.gomanifestlist
schema1
config_builder.goconfig_builder_test.gomanifest.gomanifest_test.goreference_builder.goreference_builder_test.gosign.goverify.go
schema2
versioned.gonotifications
bridge.gobridge_test.goendpoint.goevent.goevent_test.gohttp.gohttp_test.golistener.golistener_test.gometrics.gosinks.gosinks_test.go
project
reference
registry.goregistry
api
auth
client
doc.gohandlers
api_test.goapp.goapp_test.gobasicauth.gobasicauth_prego14.goblob.goblobupload.gocatalog.gocontext.gohealth_test.gohelpers.gohmac.gohmac_test.gohooks.goimages.gomail.gotags.go
listener
middleware
proxy
proxyauth.goproxyblobstore.goproxyblobstore_test.goproxymanifeststore.goproxymanifeststore_test.goproxymetrics.goproxyregistry.goproxytagservice.goproxytagservice_test.go
registry.goregistry_test.goroot.goscheduler
storage
blob_test.goblobcachemetrics.goblobserver.goblobstore.goblobwriter.goblobwriter_nonresumable.goblobwriter_resumable.gofilereader.gofilereader_test.gogarbagecollect.gogarbagecollect_test.goio.golinkedblobstore.golinkedblobstore_test.gomanifestlisthandler.gomanifeststore.gomanifeststore_test.gopaths.gopaths_test.gopurgeuploads.gopurgeuploads_test.goregistry.goschema2manifesthandler.goschema2manifesthandler_test.gosignedmanifesthandler.gotagstore.gotagstore_test.goutil.govacuum.gowalk.gowalk_test.go
cache
catalog.gocatalog_test.godoc.godriver
azure
base
factory
fileinfo.gofilesystem
gcs
inmemory
middleware
oss
s3-aws
s3-goamz
storagedriver.goswift
testdriver
testsuites
testutil
uuid
vendor.confversion
docker
LICENSENOTICEREADME.md
api
README.mdcommon.gocommon_unix.gocommon_windows.gonames.go
types
auth.go
blkiodev
client.goconfigs.gocontainer
config.gocontainer_changes.gocontainer_create.gocontainer_top.gocontainer_update.gocontainer_wait.gohost_config.gohostconfig_unix.gohostconfig_windows.go
error_response.goevents
filters
graph_driver_data.goid_response.goimage
image_delete_response_item.goimage_summary.gomount
network
plugin.goplugin_device.goplugin_env.goplugin_interface_type.goplugin_mount.goplugin_responses.goport.goregistry
seccomp.goservice_update_response.gostats.gostrslice
swarm
time
types.goversions
volume.govolume
client
README.mdcheckpoint_create.gocheckpoint_delete.gocheckpoint_list.goclient.goclient_unix.goclient_windows.gocontainer_attach.gocontainer_commit.gocontainer_copy.gocontainer_create.gocontainer_diff.gocontainer_exec.gocontainer_export.gocontainer_inspect.gocontainer_kill.gocontainer_list.gocontainer_logs.gocontainer_pause.gocontainer_prune.gocontainer_remove.gocontainer_rename.gocontainer_resize.gocontainer_restart.gocontainer_start.gocontainer_stats.gocontainer_stop.gocontainer_top.gocontainer_unpause.gocontainer_update.gocontainer_wait.godisk_usage.goerrors.goevents.gohijack.goimage_build.goimage_create.goimage_history.goimage_import.goimage_inspect.goimage_list.goimage_load.goimage_prune.goimage_pull.goimage_push.goimage_remove.goimage_save.goimage_search.goimage_tag.goinfo.gointerface.gointerface_experimental.gointerface_stable.gologin.gonetwork_connect.gonetwork_create.gonetwork_disconnect.gonetwork_inspect.gonetwork_list.gonetwork_prune.gonetwork_remove.gonode_inspect.gonode_list.gonode_remove.gonode_update.goping.goplugin_create.goplugin_disable.goplugin_enable.goplugin_inspect.goplugin_install.goplugin_list.goplugin_push.goplugin_remove.goplugin_set.goplugin_upgrade.gorequest.gosecret_create.gosecret_inspect.gosecret_list.gosecret_remove.gosecret_update.goservice_create.goservice_inspect.goservice_list.goservice_logs.goservice_remove.goservice_update.goswarm_get_unlock_key.goswarm_init.goswarm_inspect.goswarm_join.goswarm_leave.goswarm_unlock.goswarm_update.gotask_inspect.gotask_list.gotask_logs.gotransport.goutils.goversion.govolume_create.govolume_inspect.govolume_list.govolume_prune.govolume_remove.go
opts
env.gohosts.gohosts_unix.gohosts_windows.goip.gomount.goopts.goopts_unix.goopts_windows.goport.goquotedstring.goruntime.gosecret.gothrottledevice.goulimit.goweightdevice.go
pkg
README.md
httputils
ioutils
buffer.gobytespipe.gofmt.gofswriters.gomultireader.goreaders.gotemp_unix.gotemp_windows.gowriteflusher.gowriters.go
jsonlog
jsonmessage
longpath
random
stringid
system
chtimes.gochtimes_unix.gochtimes_windows.goerrors.goevents_windows.goexitcode.gofilesys.gofilesys_windows.golstat_unix.golstat_windows.gomeminfo.gomeminfo_linux.gomeminfo_solaris.gomeminfo_unsupported.gomeminfo_windows.gomknod.gomknod_windows.gopath_unix.gopath_windows.goprocess_unix.gostat_darwin.gostat_freebsd.gostat_linux.gostat_openbsd.gostat_solaris.gostat_unix.gostat_windows.gosyscall_unix.gosyscall_windows.goumask.goumask_windows.goutimes_freebsd.goutimes_linux.goutimes_unsupported.goxattrs_linux.goxattrs_unsupported.go
tarsum
term
ascii.gotc_linux_cgo.gotc_other.gotc_solaris_cgo.goterm.goterm_solaris.goterm_unix.goterm_windows.gotermios_darwin.gotermios_freebsd.gotermios_linux.gotermios_openbsd.go
windows
tlsconfig
registry
auth.goconfig.goconfig_unix.goconfig_windows.goendpoint_v1.goregistry.goservice.goservice_v1.goservice_v2.gosession.gotypes.go
vendor.confgo-connections
go-units
libtrust
gogo
protobuf
.gitignore.mailmap.travis.ymlAUTHORSCONTRIBUTORSGOLANG_CONTRIBUTORSMakefileREADMEReadme.md
_conformance
bench.mdcodec
custom_types.mdextensions.mdgogoproto
gogoreplace
install-protobuf.shio
jsonpb
plugin
compare
defaultcheck
description
embedcheck
enumstringer
equal
face
gostring
marshalto
oneofcheck
populate
size
stringer
testgen
union
unmarshal
proto
Makefileall_test.goany_test.goclone_test.godecode_test.goencode.goencode_test.goequal_test.goextensions_test.golib.gomap_test.gomessage_set_test.goproperties.go
proto3_proto
proto3_test.gosize2_test.gosize_test.gotestdata
text.gotext_parser.gotext_parser_test.gotext_test.goprotobuf
protoc-gen-combo
protoc-gen-gofast
protoc-gen-gogo
protoc-gen-gogofast
protoc-gen-gogofaster
protoc-gen-gogoslick
protoc-gen-gogotypes
protoc-gen-gostring
protoc-min-version
sortkeys
test
.gitignoreMakefile
asymetric-issue125
bug_test.gocasttype
castvalue
combos
both
marshaler
unmarshaler
custom-dash-type
custom
custombytesnonstruct
dashfilename
data
defaultconflict
embedconflict
empty-issue70
enumcustomname
enumdecl
enumdecl_all
enumprefix
enumstringer
example
extension_test.gofiledotname
fuzztests
group
importdedup
indeximport-issue72
int64support
issue260
issue261
issue262
issue312
issue322
issue330
issue34
issue42order
issue8
jsonpb-gogo
mapdefaults
mapsproto2
Makefiledoc.goheader.protomapsproto2.protomapsproto2_test.go.in
combos
both
marshaler
neither
unmarshaler
mixbench
.gitignoremarshal.txtmarshaler.txtmixbench.gooldmarshaler.txtoldunmarshaler.txtunmarshal.txtunmarshaler.txtunsafe_marshaler.txtunsafe_unmarshaler.txt
moredefaults
nopackage
oneof
oneof3
oneofembed
packed
proto3extension
protosize
registration
required
sizerconflict
sizeunderscore
stdtypes
t.gotags
theproto3
Makefiledoc.gofooter.protoheader.protomaps.protoproto3_test.go.intheproto3.proto
thetest.pb.gothetest.protothetestpb_test.gocombos
both
marshaler
neither
unmarshaler
typedecl
typedecl_all
typedeclimport
types
unmarshalmerge
unrecognized
unrecognizedgroup
uuid.gouuid_test.gotypes
Makefileany.goany.pb.goany_test.godoc.goduration.goduration.pb.goduration_gogo.goduration_test.goempty.pb.gofield_mask.pb.gostruct.pb.gotimestamp.gotimestamp.pb.gotimestamp_gogo.gotimestamp_test.gowrappers.pb.go
vanity
version
golang
protobuf
.gitignore.travis.ymlAUTHORSCONTRIBUTORSMake.protobufMakefileREADME.md
_conformance
descriptor
jsonpb
proto
Makefileall_test.goany_test.goclone_test.godecode_test.goencode_test.goequal_test.goextensions_test.gomap_test.gomessage_set_test.go
proto3_proto
proto3_test.gosize2_test.gosize_test.gotestdata
text_parser_test.gotext_test.goprotoc-gen-go
ptypes
gorilla
context
mux
matttproud
golang_protobuf_extensions
nats-io
go-nats-streaming
go-nats
.gitignore.travis.ymlLICENSETODO.mdexample_test.go
bench
enc_test.goencoders
protobuf
examples
nats.gonats_test.goscripts
staticcheck.ignoretest
auth_test.gobasic_test.gobench_test.gocluster_test.go
timer_test.goconfigs
conn_test.gocontext_test.goenc_test.gogob_test.gohelper_test.gojson_test.gomain.gonetchan_test.goprotobuf_test.goreconnect_test.gosub_test.goutil
nuid
opencontainers
openfaas
nats-queue-worker
pkg
prometheus
client_golang
.gitignore.travis.ymlAUTHORS.mdCHANGELOG.mdCONTRIBUTING.mdREADME.mdVERSION
api
prometheus
examples
prometheus
.gitignorebenchmark_test.gocounter.gocounter_test.godesc.godoc.goexample_clustermanager_test.goexamples_test.goexpvar_collector_test.gogauge.gogauge_test.gogo_collector.gogo_collector_test.gohistogram.gohistogram_test.gohttp.gohttp_test.gometric_test.goobserver.goprocess_collector.goprocess_collector_test.go
promhttp
push
registry.goregistry_test.gosummary.gosummary_test.gotimer.gountyped.govalue.govec.govec_test.goclient_model
.gitignoreCONTRIBUTING.mdMAINTAINERS.mdMakefile
cpp
metrics.protopom.xmlpython
prometheus
ruby
setup.pysrc
main
java
io
prometheus
client
common
.travis.ymlCONTRIBUTING.mdMAINTAINERS.md
config
config.gohttp_config.gohttp_config_test.go
testdata
http.conf.bearer-token-and-file-set.bad.ymlhttp.conf.empty.bad.ymlhttp.conf.good.ymlhttp.conf.invalid-bearer-token-file.bad.ymltls_config.cert_no_key.bad.ymltls_config.empty.good.ymltls_config.insecure.good.ymltls_config.invalid_field.bad.ymltls_config.key_no_cert.bad.yml
tls_config_test.goexpfmt
bench_test.godecode_test.go
fuzz
corpus
from_test_parse_0from_test_parse_1from_test_parse_2from_test_parse_3from_test_parse_4from_test_parse_error_0from_test_parse_error_1from_test_parse_error_10from_test_parse_error_11from_test_parse_error_12from_test_parse_error_13from_test_parse_error_14from_test_parse_error_15from_test_parse_error_16from_test_parse_error_17from_test_parse_error_18from_test_parse_error_19from_test_parse_error_2from_test_parse_error_3from_test_parse_error_4from_test_parse_error_5from_test_parse_error_6from_test_parse_error_7from_test_parse_error_8from_test_parse_error_9minimal
testdata
text_create_test.gotext_parse_test.gointernal
bitbucket.org
ww
goautoneg
log
model
alert_test.golabels_test.gometric_test.gosignature_test.gosilence_test.gotime.gotime_test.govalue_test.go
promlog
route
version
procfs
.travis.ymlCONTRIBUTING.mdMAINTAINERS.mdMakefile
bcache
buddyinfo.gobuddyinfo_test.gofixtures
fs_test.goipvs.goipvs_test.gomdstat_test.gomountstats_test.gonet_dev.gonet_dev_test.goproc_io.goproc_io_test.goproc_limits.goproc_limits_test.goproc_ns.goproc_ns_test.goproc_stat_test.goproc_test.gostat_test.gosysfs
ttarxfrm_test.goxfs
spf13
golang.org
x
net
sys
LICENSEPATENTSREADME
unix
README.mdasm_darwin_386.sasm_darwin_amd64.sasm_darwin_arm.sasm_darwin_arm64.sasm_dragonfly_amd64.sasm_freebsd_386.sasm_freebsd_amd64.sasm_freebsd_arm.sasm_linux_386.sasm_linux_amd64.sasm_linux_arm.sasm_linux_arm64.sasm_linux_mips64x.sasm_linux_mipsx.sasm_linux_ppc64x.sasm_linux_s390x.sasm_netbsd_386.sasm_netbsd_amd64.sasm_netbsd_arm.sasm_openbsd_386.sasm_openbsd_amd64.sasm_solaris_amd64.sbluetooth_linux.goconstants.godirent.goendian_big.goendian_little.goenv_unix.goenv_unset.goflock.goflock_linux_32bit.gogccgo.gogccgo_c.cgccgo_linux_amd64.gogccgo_linux_sparc64.goopenbsd_pledge.gorace.gorace0.gosockcmsg_linux.gosockcmsg_unix.gostr.gosyscall.gosyscall_bsd.gosyscall_darwin.gosyscall_darwin_386.gosyscall_darwin_amd64.gosyscall_darwin_arm.gosyscall_darwin_arm64.gosyscall_dragonfly.gosyscall_dragonfly_amd64.gosyscall_freebsd.gosyscall_freebsd_386.gosyscall_freebsd_amd64.gosyscall_freebsd_arm.gosyscall_linux.gosyscall_linux_386.gosyscall_linux_amd64.gosyscall_linux_amd64_gc.gosyscall_linux_arm.gosyscall_linux_arm64.gosyscall_linux_mips64x.gosyscall_linux_mipsx.gosyscall_linux_ppc64x.gosyscall_linux_s390x.gosyscall_linux_sparc64.gosyscall_netbsd.gosyscall_netbsd_386.gosyscall_netbsd_amd64.gosyscall_netbsd_arm.gosyscall_no_getwd.gosyscall_openbsd.gosyscall_openbsd_386.gosyscall_openbsd_amd64.gosyscall_solaris.gosyscall_solaris_amd64.gosyscall_unix.gosyscall_unix_gc.gozerrors_darwin_386.gozerrors_darwin_amd64.gozerrors_darwin_arm.gozerrors_darwin_arm64.gozerrors_dragonfly_amd64.gozerrors_freebsd_386.gozerrors_freebsd_amd64.gozerrors_freebsd_arm.gozerrors_linux_386.gozerrors_linux_amd64.gozerrors_linux_arm.gozerrors_linux_arm64.gozerrors_linux_mips.gozerrors_linux_mips64.gozerrors_linux_mips64le.gozerrors_linux_mipsle.gozerrors_linux_ppc64.gozerrors_linux_ppc64le.gozerrors_linux_s390x.gozerrors_linux_sparc64.gozerrors_netbsd_386.gozerrors_netbsd_amd64.gozerrors_netbsd_arm.gozerrors_openbsd_386.gozerrors_openbsd_amd64.gozerrors_solaris_amd64.gozsyscall_darwin_386.gozsyscall_darwin_amd64.gozsyscall_darwin_arm.gozsyscall_darwin_arm64.gozsyscall_dragonfly_amd64.gozsyscall_freebsd_386.gozsyscall_freebsd_amd64.gozsyscall_freebsd_arm.gozsyscall_linux_386.gozsyscall_linux_amd64.gozsyscall_linux_arm.gozsyscall_linux_arm64.gozsyscall_linux_mips.gozsyscall_linux_mips64.gozsyscall_linux_mips64le.gozsyscall_linux_mipsle.gozsyscall_linux_ppc64.gozsyscall_linux_ppc64le.gozsyscall_linux_s390x.gozsyscall_linux_sparc64.gozsyscall_netbsd_386.gozsyscall_netbsd_amd64.gozsyscall_netbsd_arm.gozsyscall_openbsd_386.gozsyscall_openbsd_amd64.gozsyscall_solaris_amd64.gozsysctl_openbsd.gozsysnum_darwin_386.gozsysnum_darwin_amd64.gozsysnum_darwin_arm.gozsysnum_darwin_arm64.gozsysnum_dragonfly_amd64.gozsysnum_freebsd_386.gozsysnum_freebsd_amd64.gozsysnum_freebsd_arm.gozsysnum_linux_386.gozsysnum_linux_amd64.gozsysnum_linux_arm.gozsysnum_linux_arm64.gozsysnum_linux_mips.gozsysnum_linux_mips64.gozsysnum_linux_mips64le.gozsysnum_linux_mipsle.gozsysnum_linux_ppc64.gozsysnum_linux_ppc64le.gozsysnum_linux_s390x.gozsysnum_linux_sparc64.gozsysnum_netbsd_386.gozsysnum_netbsd_amd64.gozsysnum_netbsd_arm.gozsysnum_openbsd_386.gozsysnum_openbsd_amd64.gozsysnum_solaris_amd64.goztypes_darwin_386.goztypes_darwin_amd64.goztypes_darwin_arm.goztypes_darwin_arm64.goztypes_dragonfly_amd64.goztypes_freebsd_386.goztypes_freebsd_amd64.goztypes_freebsd_arm.goztypes_linux_386.goztypes_linux_amd64.goztypes_linux_arm.goztypes_linux_arm64.goztypes_linux_mips.goztypes_linux_mips64.goztypes_linux_mips64le.goztypes_linux_mipsle.goztypes_linux_ppc64.goztypes_linux_ppc64le.goztypes_linux_s390x.goztypes_linux_sparc64.goztypes_netbsd_386.goztypes_netbsd_amd64.goztypes_netbsd_arm.goztypes_openbsd_386.goztypes_openbsd_amd64.goztypes_solaris_amd64.go
windows
prometheus
300
gateway/vendor/github.com/golang/protobuf/proto/any_test.go
generated
vendored
Normal file
300
gateway/vendor/github.com/golang/protobuf/proto/any_test.go
generated
vendored
Normal file
@ -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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user