chore(*): make everything use goven

for i in github.com/BurntSushi/toml github.com/coreos/go-etcd/etcd github.com/coreos/go-log/log github.com/gorilla/context github.com/rcrowley/go-metrics bitbucket.org/kardianos/osext github.com/coreos/go-systemd/journal github.com/coreos/raft code.google.com/p/goprotobuf/proto ; do goven  -copy -rewrite $i; done
This commit is contained in:
Brandon Philips
2014-02-01 22:50:15 -08:00
parent ea8a353545
commit 13b6c1e684
536 changed files with 4193 additions and 88349 deletions

View File

@@ -5,7 +5,7 @@ import (
"log" "log"
"strconv" "strconv"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
func write(endpoint string, requests int, end chan int) { func write(endpoint string, requests int, end chan int) {

View File

@@ -24,7 +24,7 @@ import (
"runtime" "runtime"
"time" "time"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
ehttp "github.com/coreos/etcd/http" ehttp "github.com/coreos/etcd/http"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"

View File

@@ -1,7 +1,7 @@
package log package log
import ( import (
golog "github.com/coreos/go-log/log" golog "github.com/coreos/etcd/third_party/github.com/coreos/go-log/log"
"os" "os"
) )

View File

@@ -7,7 +7,7 @@ package metrics
import ( import (
"io" "io"
gometrics "github.com/rcrowley/go-metrics" gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
) )
type Timer gometrics.Timer type Timer gometrics.Timer

View File

@@ -3,7 +3,7 @@ package metrics
import ( import (
"io" "io"
gometrics "github.com/rcrowley/go-metrics" gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
) )
type nilBucket struct{} type nilBucket struct{}

View File

@@ -6,25 +6,25 @@ import (
"sync" "sync"
"time" "time"
gometrics "github.com/rcrowley/go-metrics" gometrics "github.com/coreos/etcd/third_party/github.com/rcrowley/go-metrics"
) )
const ( const (
// RuntimeMemStatsSampleInterval is the interval in seconds at which the // RuntimeMemStatsSampleInterval is the interval in seconds at which the
// Go runtime's memory statistics will be gathered. // Go runtime's memory statistics will be gathered.
RuntimeMemStatsSampleInterval = time.Duration(2) * time.Second RuntimeMemStatsSampleInterval = time.Duration(2) * time.Second
// GraphitePublishInterval is the interval in seconds at which all // GraphitePublishInterval is the interval in seconds at which all
// gathered statistics will be published to a Graphite endpoint. // gathered statistics will be published to a Graphite endpoint.
GraphitePublishInterval = time.Duration(2) * time.Second GraphitePublishInterval = time.Duration(2) * time.Second
) )
type standardBucket struct { type standardBucket struct {
sync.Mutex sync.Mutex
name string name string
registry gometrics.Registry registry gometrics.Registry
timers map[string]Timer timers map[string]Timer
gauges map[string]Gauge gauges map[string]Gauge
} }
func newStandardBucket(name string) standardBucket { func newStandardBucket(name string) standardBucket {
@@ -34,10 +34,10 @@ func newStandardBucket(name string) standardBucket {
go gometrics.CaptureRuntimeMemStats(registry, RuntimeMemStatsSampleInterval) go gometrics.CaptureRuntimeMemStats(registry, RuntimeMemStatsSampleInterval)
return standardBucket{ return standardBucket{
name: name, name: name,
registry: registry, registry: registry,
timers: make(map[string]Timer), timers: make(map[string]Timer),
gauges: make(map[string]Gauge), gauges: make(map[string]Gauge),
} }
} }

View File

@@ -7,7 +7,7 @@ import (
"net/url" "net/url"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// deleteHandler remove a given leader. // deleteHandler remove a given leader.

View File

@@ -5,7 +5,7 @@ import (
"io" "io"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// getHandler retrieves the current leader. // getHandler retrieves the current leader.

View File

@@ -4,7 +4,7 @@ import (
"net/http" "net/http"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// prefix is appended to the lock's prefix since the leader mod uses the lock mod. // prefix is appended to the lock's prefix since the leader mod uses the lock mod.
@@ -13,19 +13,19 @@ const prefix = "/_mod/leader"
// handler manages the leader HTTP request. // handler manages the leader HTTP request.
type handler struct { type handler struct {
*mux.Router *mux.Router
client *http.Client client *http.Client
transport *http.Transport transport *http.Transport
addr string addr string
} }
// NewHandler creates an HTTP handler that can be registered on a router. // NewHandler creates an HTTP handler that can be registered on a router.
func NewHandler(addr string) http.Handler { func NewHandler(addr string) http.Handler {
transport := &http.Transport{DisableKeepAlives: false} transport := &http.Transport{DisableKeepAlives: false}
h := &handler{ h := &handler{
Router: mux.NewRouter(), Router: mux.NewRouter(),
client: &http.Client{Transport: transport}, client: &http.Client{Transport: transport},
transport: transport, transport: transport,
addr: addr, addr: addr,
} }
h.StrictSlash(false) h.StrictSlash(false)
h.handleFunc("/{key:.*}", h.getHandler).Methods("GET") h.handleFunc("/{key:.*}", h.getHandler).Methods("GET")

View File

@@ -7,7 +7,7 @@ import (
"net/url" "net/url"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// setHandler attempts to set the current leader. // setHandler attempts to set the current leader.

View File

@@ -9,8 +9,8 @@ import (
"time" "time"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// acquireHandler attempts to acquire a lock on the given key. // acquireHandler attempts to acquire a lock on the given key.

View File

@@ -5,7 +5,7 @@ import (
"path" "path"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// getIndexHandler retrieves the current lock index. // getIndexHandler retrieves the current lock index.

View File

@@ -4,8 +4,8 @@ import (
"net/http" "net/http"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
const prefix = "/_etcd/mod/lock" const prefix = "/_etcd/mod/lock"
@@ -13,14 +13,14 @@ const prefix = "/_etcd/mod/lock"
// handler manages the lock HTTP request. // handler manages the lock HTTP request.
type handler struct { type handler struct {
*mux.Router *mux.Router
client *etcd.Client client *etcd.Client
} }
// NewHandler creates an HTTP handler that can be registered on a router. // NewHandler creates an HTTP handler that can be registered on a router.
func NewHandler(addr string) http.Handler { func NewHandler(addr string) http.Handler {
h := &handler{ h := &handler{
Router: mux.NewRouter(), Router: mux.NewRouter(),
client: etcd.NewClient([]string{addr}), client: etcd.NewClient([]string{addr}),
} }
h.StrictSlash(false) h.StrictSlash(false)
h.handleFunc("/{key:.*}", h.getIndexHandler).Methods("GET") h.handleFunc("/{key:.*}", h.getIndexHandler).Methods("GET")

View File

@@ -5,7 +5,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// lockNodes is a wrapper for go-etcd's Nodes to allow for sorting by numeric key. // lockNodes is a wrapper for go-etcd's Nodes to allow for sorting by numeric key.

View File

@@ -5,7 +5,7 @@ import (
"path" "path"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// releaseLockHandler deletes the lock. // releaseLockHandler deletes the lock.

View File

@@ -6,7 +6,7 @@ import (
"strconv" "strconv"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// renewLockHandler attempts to update the TTL on an existing lock. // renewLockHandler attempts to update the TTL on an existing lock.

View File

@@ -8,7 +8,7 @@ import (
"github.com/coreos/etcd/mod/dashboard" "github.com/coreos/etcd/mod/dashboard"
leader2 "github.com/coreos/etcd/mod/leader/v2" leader2 "github.com/coreos/etcd/mod/leader/v2"
lock2 "github.com/coreos/etcd/mod/lock/v2" lock2 "github.com/coreos/etcd/mod/lock/v2"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
var ServeMux *http.Handler var ServeMux *http.Handler

View File

@@ -13,7 +13,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/BurntSushi/toml" "github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
) )
@@ -22,63 +22,63 @@ const DefaultSystemConfigPath = "/etc/etcd/etcd.conf"
// A lookup of deprecated flags to their new flag name. // A lookup of deprecated flags to their new flag name.
var newFlagNameLookup = map[string]string{ var newFlagNameLookup = map[string]string{
"C": "peers", "C": "peers",
"CF": "peers-file", "CF": "peers-file",
"n": "name", "n": "name",
"c": "addr", "c": "addr",
"cl": "bind-addr", "cl": "bind-addr",
"s": "peer-addr", "s": "peer-addr",
"sl": "peer-bind-addr", "sl": "peer-bind-addr",
"d": "data-dir", "d": "data-dir",
"m": "max-result-buffer", "m": "max-result-buffer",
"r": "max-retry-attempts", "r": "max-retry-attempts",
"maxsize": "max-cluster-size", "maxsize": "max-cluster-size",
"clientCAFile": "ca-file", "clientCAFile": "ca-file",
"clientCert": "cert-file", "clientCert": "cert-file",
"clientKey": "key-file", "clientKey": "key-file",
"serverCAFile": "peer-ca-file", "serverCAFile": "peer-ca-file",
"serverCert": "peer-cert-file", "serverCert": "peer-cert-file",
"serverKey": "peer-key-file", "serverKey": "peer-key-file",
"snapshotCount": "snapshot-count", "snapshotCount": "snapshot-count",
} }
// Config represents the server configuration. // Config represents the server configuration.
type Config struct { type Config struct {
SystemPath string SystemPath string
Addr string `toml:"addr" env:"ETCD_ADDR"` Addr string `toml:"addr" env:"ETCD_ADDR"`
BindAddr string `toml:"bind_addr" env:"ETCD_BIND_ADDR"` BindAddr string `toml:"bind_addr" env:"ETCD_BIND_ADDR"`
CAFile string `toml:"ca_file" env:"ETCD_CA_FILE"` CAFile string `toml:"ca_file" env:"ETCD_CA_FILE"`
CertFile string `toml:"cert_file" env:"ETCD_CERT_FILE"` CertFile string `toml:"cert_file" env:"ETCD_CERT_FILE"`
CPUProfileFile string CPUProfileFile string
CorsOrigins []string `toml:"cors" env:"ETCD_CORS"` CorsOrigins []string `toml:"cors" env:"ETCD_CORS"`
DataDir string `toml:"data_dir" env:"ETCD_DATA_DIR"` DataDir string `toml:"data_dir" env:"ETCD_DATA_DIR"`
Force bool Force bool
KeyFile string `toml:"key_file" env:"ETCD_KEY_FILE"` KeyFile string `toml:"key_file" env:"ETCD_KEY_FILE"`
Peers []string `toml:"peers" env:"ETCD_PEERS"` Peers []string `toml:"peers" env:"ETCD_PEERS"`
PeersFile string `toml:"peers_file" env:"ETCD_PEERS_FILE"` PeersFile string `toml:"peers_file" env:"ETCD_PEERS_FILE"`
MaxClusterSize int `toml:"max_cluster_size" env:"ETCD_MAX_CLUSTER_SIZE"` MaxClusterSize int `toml:"max_cluster_size" env:"ETCD_MAX_CLUSTER_SIZE"`
MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"` MaxResultBuffer int `toml:"max_result_buffer" env:"ETCD_MAX_RESULT_BUFFER"`
MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"` MaxRetryAttempts int `toml:"max_retry_attempts" env:"ETCD_MAX_RETRY_ATTEMPTS"`
Name string `toml:"name" env:"ETCD_NAME"` Name string `toml:"name" env:"ETCD_NAME"`
Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"` Snapshot bool `toml:"snapshot" env:"ETCD_SNAPSHOT"`
SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"` SnapshotCount int `toml:"snapshot_count" env:"ETCD_SNAPSHOTCOUNT"`
ShowHelp bool ShowHelp bool
ShowVersion bool ShowVersion bool
Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"` Verbose bool `toml:"verbose" env:"ETCD_VERBOSE"`
VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"` VeryVerbose bool `toml:"very_verbose" env:"ETCD_VERY_VERBOSE"`
VeryVeryVerbose bool `toml:"very_very_verbose" env:"ETCD_VERY_VERY_VERBOSE"` VeryVeryVerbose bool `toml:"very_very_verbose" env:"ETCD_VERY_VERY_VERBOSE"`
Peer struct { Peer struct {
Addr string `toml:"addr" env:"ETCD_PEER_ADDR"` Addr string `toml:"addr" env:"ETCD_PEER_ADDR"`
BindAddr string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"` BindAddr string `toml:"bind_addr" env:"ETCD_PEER_BIND_ADDR"`
CAFile string `toml:"ca_file" env:"ETCD_PEER_CA_FILE"` CAFile string `toml:"ca_file" env:"ETCD_PEER_CA_FILE"`
CertFile string `toml:"cert_file" env:"ETCD_PEER_CERT_FILE"` CertFile string `toml:"cert_file" env:"ETCD_PEER_CERT_FILE"`
KeyFile string `toml:"key_file" env:"ETCD_PEER_KEY_FILE"` KeyFile string `toml:"key_file" env:"ETCD_PEER_KEY_FILE"`
HeartbeatTimeout int `toml:"heartbeat_timeout" env:"ETCD_PEER_HEARTBEAT_TIMEOUT"` HeartbeatTimeout int `toml:"heartbeat_timeout" env:"ETCD_PEER_HEARTBEAT_TIMEOUT"`
ElectionTimeout int `toml:"election_timeout" env:"ETCD_PEER_ELECTION_TIMEOUT"` ElectionTimeout int `toml:"election_timeout" env:"ETCD_PEER_ELECTION_TIMEOUT"`
} }
strTrace string `toml:"trace" env:"ETCD_TRACE"` strTrace string `toml:"trace" env:"ETCD_TRACE"`
GraphiteHost string `toml:"graphite_host" env:"ETCD_GRAPHITE_HOST"` GraphiteHost string `toml:"graphite_host" env:"ETCD_GRAPHITE_HOST"`
} }
// NewConfig returns a Config initialized with default values. // NewConfig returns a Config initialized with default values.
@@ -433,9 +433,9 @@ func (c *Config) Sanitize() error {
// TLSInfo retrieves a TLSInfo object for the client server. // TLSInfo retrieves a TLSInfo object for the client server.
func (c *Config) TLSInfo() TLSInfo { func (c *Config) TLSInfo() TLSInfo {
return TLSInfo{ return TLSInfo{
CAFile: c.CAFile, CAFile: c.CAFile,
CertFile: c.CertFile, CertFile: c.CertFile,
KeyFile: c.KeyFile, KeyFile: c.KeyFile,
} }
} }
@@ -447,9 +447,9 @@ func (c *Config) TLSConfig() (TLSConfig, error) {
// PeerTLSInfo retrieves a TLSInfo object for the peer server. // PeerTLSInfo retrieves a TLSInfo object for the peer server.
func (c *Config) PeerTLSInfo() TLSInfo { func (c *Config) PeerTLSInfo() TLSInfo {
return TLSInfo{ return TLSInfo{
CAFile: c.Peer.CAFile, CAFile: c.Peer.CAFile,
CertFile: c.Peer.CertFile, CertFile: c.Peer.CertFile,
KeyFile: c.Peer.KeyFile, KeyFile: c.Peer.KeyFile,
} }
} }

View File

@@ -5,7 +5,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/BurntSushi/toml" "github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )

View File

@@ -5,7 +5,7 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -14,20 +14,20 @@ func init() {
// The JoinCommand adds a node to the cluster. // The JoinCommand adds a node to the cluster.
type JoinCommand struct { type JoinCommand struct {
MinVersion int `json:"minVersion"` MinVersion int `json:"minVersion"`
MaxVersion int `json:"maxVersion"` MaxVersion int `json:"maxVersion"`
Name string `json:"name"` Name string `json:"name"`
RaftURL string `json:"raftURL"` RaftURL string `json:"raftURL"`
EtcdURL string `json:"etcdURL"` EtcdURL string `json:"etcdURL"`
} }
func NewJoinCommand(minVersion int, maxVersion int, name, raftUrl, etcdUrl string) *JoinCommand { func NewJoinCommand(minVersion int, maxVersion int, name, raftUrl, etcdUrl string) *JoinCommand {
return &JoinCommand{ return &JoinCommand{
MinVersion: minVersion, MinVersion: minVersion,
MaxVersion: maxVersion, MaxVersion: maxVersion,
Name: name, Name: name,
RaftURL: raftUrl, RaftURL: raftUrl,
EtcdURL: etcdUrl, EtcdURL: etcdUrl,
} }
} }

View File

@@ -11,8 +11,8 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
@@ -25,55 +25,55 @@ const retryInterval = 10
const ThresholdMonitorTimeout = 5 * time.Second const ThresholdMonitorTimeout = 5 * time.Second
type PeerServerConfig struct { type PeerServerConfig struct {
Name string Name string
Scheme string Scheme string
URL string URL string
SnapshotCount int SnapshotCount int
MaxClusterSize int MaxClusterSize int
RetryTimes int RetryTimes int
} }
type PeerServer struct { type PeerServer struct {
Config PeerServerConfig Config PeerServerConfig
raftServer raft.Server raftServer raft.Server
server *Server server *Server
joinIndex uint64 joinIndex uint64
followersStats *raftFollowersStats followersStats *raftFollowersStats
serverStats *raftServerStats serverStats *raftServerStats
registry *Registry registry *Registry
store store.Store store store.Store
snapConf *snapshotConf snapConf *snapshotConf
closeChan chan bool closeChan chan bool
timeoutThresholdChan chan interface{} timeoutThresholdChan chan interface{}
metrics *metrics.Bucket metrics *metrics.Bucket
} }
// TODO: find a good policy to do snapshot // TODO: find a good policy to do snapshot
type snapshotConf struct { type snapshotConf struct {
// Etcd will check if snapshot is need every checkingInterval // Etcd will check if snapshot is need every checkingInterval
checkingInterval time.Duration checkingInterval time.Duration
// The index when the last snapshot happened // The index when the last snapshot happened
lastIndex uint64 lastIndex uint64
// If the incremental number of index since the last snapshot // If the incremental number of index since the last snapshot
// exceeds the snapshot Threshold, etcd will do a snapshot // exceeds the snapshot Threshold, etcd will do a snapshot
snapshotThr uint64 snapshotThr uint64
} }
func NewPeerServer(psConfig PeerServerConfig, registry *Registry, store store.Store, mb *metrics.Bucket, followersStats *raftFollowersStats, serverStats *raftServerStats) *PeerServer { func NewPeerServer(psConfig PeerServerConfig, registry *Registry, store store.Store, mb *metrics.Bucket, followersStats *raftFollowersStats, serverStats *raftServerStats) *PeerServer {
s := &PeerServer{ s := &PeerServer{
Config: psConfig, Config: psConfig,
registry: registry, registry: registry,
store: store, store: store,
followersStats: followersStats, followersStats: followersStats,
serverStats: serverStats, serverStats: serverStats,
timeoutThresholdChan: make(chan interface{}, 1), timeoutThresholdChan: make(chan interface{}, 1),
metrics: mb, metrics: mb,
} }
return s return s
@@ -81,10 +81,10 @@ func NewPeerServer(psConfig PeerServerConfig, registry *Registry, store store.St
func (s *PeerServer) SetRaftServer(raftServer raft.Server) { func (s *PeerServer) SetRaftServer(raftServer raft.Server) {
s.snapConf = &snapshotConf{ s.snapConf = &snapshotConf{
checkingInterval: time.Second * 3, checkingInterval: time.Second * 3,
// this is not accurate, we will update raft to provide an api // this is not accurate, we will update raft to provide an api
lastIndex: raftServer.CommitIndex(), lastIndex: raftServer.CommitIndex(),
snapshotThr: uint64(s.Config.SnapshotCount), snapshotThr: uint64(s.Config.SnapshotCount),
} }
raftServer.AddEventListener(raft.StateChangeEventType, s.raftEventLogger) raftServer.AddEventListener(raft.StateChangeEventType, s.raftEventLogger)

View File

@@ -9,8 +9,8 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// Get all the current logs // Get all the current logs

View File

@@ -3,36 +3,36 @@ package server
import ( import (
"time" "time"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
type raftServerStats struct { type raftServerStats struct {
Name string `json:"name"` Name string `json:"name"`
State string `json:"state"` State string `json:"state"`
StartTime time.Time `json:"startTime"` StartTime time.Time `json:"startTime"`
LeaderInfo struct { LeaderInfo struct {
Name string `json:"leader"` Name string `json:"leader"`
Uptime string `json:"uptime"` Uptime string `json:"uptime"`
startTime time.Time startTime time.Time
} `json:"leaderInfo"` } `json:"leaderInfo"`
RecvAppendRequestCnt uint64 `json:"recvAppendRequestCnt,"` RecvAppendRequestCnt uint64 `json:"recvAppendRequestCnt,"`
RecvingPkgRate float64 `json:"recvPkgRate,omitempty"` RecvingPkgRate float64 `json:"recvPkgRate,omitempty"`
RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"` RecvingBandwidthRate float64 `json:"recvBandwidthRate,omitempty"`
SendAppendRequestCnt uint64 `json:"sendAppendRequestCnt"` SendAppendRequestCnt uint64 `json:"sendAppendRequestCnt"`
SendingPkgRate float64 `json:"sendPkgRate,omitempty"` SendingPkgRate float64 `json:"sendPkgRate,omitempty"`
SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"` SendingBandwidthRate float64 `json:"sendBandwidthRate,omitempty"`
sendRateQueue *statsQueue sendRateQueue *statsQueue
recvRateQueue *statsQueue recvRateQueue *statsQueue
} }
func NewRaftServerStats(name string) *raftServerStats { func NewRaftServerStats(name string) *raftServerStats {
return &raftServerStats{ return &raftServerStats{
Name: name, Name: name,
StartTime: time.Now(), StartTime: time.Now(),
sendRateQueue: &statsQueue{ sendRateQueue: &statsQueue{
back: -1, back: -1,
}, },

View File

@@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {

View File

@@ -8,8 +8,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
@@ -23,26 +23,26 @@ import (
// This is the default implementation of the Server interface. // This is the default implementation of the Server interface.
type Server struct { type Server struct {
Name string Name string
url string url string
handler http.Handler handler http.Handler
peerServer *PeerServer peerServer *PeerServer
registry *Registry registry *Registry
store store.Store store store.Store
metrics *metrics.Bucket metrics *metrics.Bucket
trace bool trace bool
} }
// Creates a new Server. // Creates a new Server.
func New(name, url string, peerServer *PeerServer, registry *Registry, store store.Store, mb *metrics.Bucket) *Server { func New(name, url string, peerServer *PeerServer, registry *Registry, store store.Store, mb *metrics.Bucket) *Server {
s := &Server{ s := &Server{
Name: name, Name: name,
url: url, url: url,
store: store, store: store,
registry: registry, registry: registry,
peerServer: peerServer, peerServer: peerServer,
metrics: mb, metrics: mb,
} }
return s return s

View File

@@ -10,18 +10,18 @@ import (
"time" "time"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
// Transporter layer for communication between raft nodes // Transporter layer for communication between raft nodes
type transporter struct { type transporter struct {
requestTimeout time.Duration requestTimeout time.Duration
followersStats *raftFollowersStats followersStats *raftFollowersStats
serverStats *raftServerStats serverStats *raftServerStats
registry *Registry registry *Registry
client *http.Client client *http.Client
transport *http.Transport transport *http.Transport
} }
type dialer func(network, addr string) (net.Conn, error) type dialer func(network, addr string) (net.Conn, error)
@@ -34,16 +34,16 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
Dial: func(network, addr string) (net.Conn, error) { Dial: func(network, addr string) (net.Conn, error) {
return net.DialTimeout(network, addr, dialTimeout) return net.DialTimeout(network, addr, dialTimeout)
}, },
ResponseHeaderTimeout: responseHeaderTimeout, ResponseHeaderTimeout: responseHeaderTimeout,
} }
t := transporter{ t := transporter{
client: &http.Client{Transport: tr}, client: &http.Client{Transport: tr},
transport: tr, transport: tr,
requestTimeout: requestTimeout, requestTimeout: requestTimeout,
followersStats: followersStats, followersStats: followersStats,
serverStats: serverStats, serverStats: serverStats,
registry: registry, registry: registry,
} }
return &t return &t
@@ -73,7 +73,7 @@ func (t *transporter) SendAppendEntriesRequest(server raft.Server, peer *raft.Pe
thisFollowerStats, ok := t.followersStats.Followers[peer.Name] thisFollowerStats, ok := t.followersStats.Followers[peer.Name]
if !ok { //this is the first time this follower has been seen if !ok { //this is the first time this follower has been seen
thisFollowerStats = &raftFollowerStats{} thisFollowerStats = &raftFollowerStats{}
thisFollowerStats.Latency.Minimum = 1 << 63 thisFollowerStats.Latency.Minimum = 1 << 63
t.followersStats.Followers[peer.Name] = thisFollowerStats t.followersStats.Followers[peer.Name] = thisFollowerStats

View File

@@ -1,7 +1,7 @@
package v1 package v1
import ( import (
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
"net/http" "net/http"
) )

View File

@@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// Retrieves the value for a given key. // Retrieves the value for a given key.

View File

@@ -5,8 +5,8 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// Sets the value for a given key. // Sets the value for a given key.

View File

@@ -2,7 +2,7 @@ package v1
import ( import (
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"net/http" "net/http"
) )

View File

@@ -6,7 +6,7 @@ import (
"strconv" "strconv"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
// Watches a given key prefix for changes. // Watches a given key prefix for changes.

View File

@@ -5,7 +5,7 @@ import (
"strconv" "strconv"
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
func DeleteHandler(w http.ResponseWriter, req *http.Request, s Server) error { func DeleteHandler(w http.ResponseWriter, req *http.Request, s Server) error {

View File

@@ -9,8 +9,8 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error { func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {

View File

@@ -5,7 +5,7 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
func PostHandler(w http.ResponseWriter, req *http.Request, s Server) error { func PostHandler(w http.ResponseWriter, req *http.Request, s Server) error {

View File

@@ -7,8 +7,8 @@ import (
etcdErr "github.com/coreos/etcd/error" etcdErr "github.com/coreos/etcd/error"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/gorilla/mux" "github.com/coreos/etcd/third_party/github.com/gorilla/mux"
) )
func PutHandler(w http.ResponseWriter, req *http.Request, s Server) error { func PutHandler(w http.ResponseWriter, req *http.Request, s Server) error {

View File

@@ -2,7 +2,7 @@ package v2
import ( import (
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"net/http" "net/http"
) )

View File

@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
// A lookup of factories by version. // A lookup of factories by version.

View File

@@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -28,59 +28,59 @@ func (f *CommandFactory) CreateUpgradeCommand() raft.Command {
// CreateSetCommand creates a version 2 command to set a key to a given value in the store. // CreateSetCommand creates a version 2 command to set a key to a given value in the store.
func (f *CommandFactory) CreateSetCommand(key string, dir bool, value string, expireTime time.Time) raft.Command { func (f *CommandFactory) CreateSetCommand(key string, dir bool, value string, expireTime time.Time) raft.Command {
return &SetCommand{ return &SetCommand{
Key: key, Key: key,
Value: value, Value: value,
ExpireTime: expireTime, ExpireTime: expireTime,
Dir: dir, Dir: dir,
} }
} }
// CreateCreateCommand creates a version 2 command to create a new key in the store. // CreateCreateCommand creates a version 2 command to create a new key in the store.
func (f *CommandFactory) CreateCreateCommand(key string, dir bool, value string, expireTime time.Time, unique bool) raft.Command { func (f *CommandFactory) CreateCreateCommand(key string, dir bool, value string, expireTime time.Time, unique bool) raft.Command {
return &CreateCommand{ return &CreateCommand{
Key: key, Key: key,
Value: value, Value: value,
ExpireTime: expireTime, ExpireTime: expireTime,
Unique: unique, Unique: unique,
Dir: dir, Dir: dir,
} }
} }
// CreateUpdateCommand creates a version 2 command to update a key to a given value in the store. // CreateUpdateCommand creates a version 2 command to update a key to a given value in the store.
func (f *CommandFactory) CreateUpdateCommand(key string, value string, expireTime time.Time) raft.Command { func (f *CommandFactory) CreateUpdateCommand(key string, value string, expireTime time.Time) raft.Command {
return &UpdateCommand{ return &UpdateCommand{
Key: key, Key: key,
Value: value, Value: value,
ExpireTime: expireTime, ExpireTime: expireTime,
} }
} }
// CreateDeleteCommand creates a version 2 command to delete a key from the store. // CreateDeleteCommand creates a version 2 command to delete a key from the store.
func (f *CommandFactory) CreateDeleteCommand(key string, dir, recursive bool) raft.Command { func (f *CommandFactory) CreateDeleteCommand(key string, dir, recursive bool) raft.Command {
return &DeleteCommand{ return &DeleteCommand{
Key: key, Key: key,
Recursive: recursive, Recursive: recursive,
Dir: dir, Dir: dir,
} }
} }
// CreateCompareAndSwapCommand creates a version 2 command to conditionally set a key in the store. // CreateCompareAndSwapCommand creates a version 2 command to conditionally set a key in the store.
func (f *CommandFactory) CreateCompareAndSwapCommand(key string, value string, prevValue string, prevIndex uint64, expireTime time.Time) raft.Command { func (f *CommandFactory) CreateCompareAndSwapCommand(key string, value string, prevValue string, prevIndex uint64, expireTime time.Time) raft.Command {
return &CompareAndSwapCommand{ return &CompareAndSwapCommand{
Key: key, Key: key,
Value: value, Value: value,
PrevValue: prevValue, PrevValue: prevValue,
PrevIndex: prevIndex, PrevIndex: prevIndex,
ExpireTime: expireTime, ExpireTime: expireTime,
} }
} }
// CreateCompareAndDeleteCommand creates a version 2 command to conditionally delete a key from the store. // CreateCompareAndDeleteCommand creates a version 2 command to conditionally delete a key from the store.
func (f *CommandFactory) CreateCompareAndDeleteCommand(key string, prevValue string, prevIndex uint64) raft.Command { func (f *CommandFactory) CreateCompareAndDeleteCommand(key string, prevValue string, prevIndex uint64) raft.Command {
return &CompareAndDeleteCommand{ return &CompareAndDeleteCommand{
Key: key, Key: key,
PrevValue: prevValue, PrevValue: prevValue,
PrevIndex: prevIndex, PrevIndex: prevIndex,
} }
} }

View File

@@ -3,7 +3,7 @@ package v2
import ( import (
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -12,9 +12,9 @@ func init() {
// The CompareAndDelete performs a conditional delete on a key in the store. // The CompareAndDelete performs a conditional delete on a key in the store.
type CompareAndDeleteCommand struct { type CompareAndDeleteCommand struct {
Key string `json:"key"` Key string `json:"key"`
PrevValue string `json:"prevValue"` PrevValue string `json:"prevValue"`
PrevIndex uint64 `json:"prevIndex"` PrevIndex uint64 `json:"prevIndex"`
} }
// The name of the compareAndDelete command in the log // The name of the compareAndDelete command in the log

View File

@@ -5,7 +5,7 @@ import (
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -14,11 +14,11 @@ func init() {
// The CompareAndSwap performs a conditional update on a key in the store. // The CompareAndSwap performs a conditional update on a key in the store.
type CompareAndSwapCommand struct { type CompareAndSwapCommand struct {
Key string `json:"key"` Key string `json:"key"`
Value string `json:"value"` Value string `json:"value"`
ExpireTime time.Time `json:"expireTime"` ExpireTime time.Time `json:"expireTime"`
PrevValue string `json:"prevValue"` PrevValue string `json:"prevValue"`
PrevIndex uint64 `json:"prevIndex"` PrevIndex uint64 `json:"prevIndex"`
} }
// The name of the testAndSet command in the log // The name of the testAndSet command in the log

View File

@@ -5,7 +5,7 @@ import (
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -14,11 +14,11 @@ func init() {
// Create command // Create command
type CreateCommand struct { type CreateCommand struct {
Key string `json:"key"` Key string `json:"key"`
Value string `json:"value"` Value string `json:"value"`
ExpireTime time.Time `json:"expireTime"` ExpireTime time.Time `json:"expireTime"`
Unique bool `json:"unique"` Unique bool `json:"unique"`
Dir bool `json:"dir"` Dir bool `json:"dir"`
} }
// The name of the create command in the log // The name of the create command in the log

View File

@@ -3,7 +3,7 @@ package v2
import ( import (
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -12,9 +12,9 @@ func init() {
// The DeleteCommand removes a key from the Store. // The DeleteCommand removes a key from the Store.
type DeleteCommand struct { type DeleteCommand struct {
Key string `json:"key"` Key string `json:"key"`
Recursive bool `json:"recursive"` Recursive bool `json:"recursive"`
Dir bool `json:"dir"` Dir bool `json:"dir"`
} }
// The name of the delete command in the log // The name of the delete command in the log

View File

@@ -5,7 +5,7 @@ import (
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {
@@ -14,10 +14,10 @@ func init() {
// Create command // Create command
type SetCommand struct { type SetCommand struct {
Key string `json:"key"` Key string `json:"key"`
Value string `json:"value"` Value string `json:"value"`
ExpireTime time.Time `json:"expireTime"` ExpireTime time.Time `json:"expireTime"`
Dir bool `json:"dir"` Dir bool `json:"dir"`
} }
// The name of the create command in the log // The name of the create command in the log

View File

@@ -4,7 +4,7 @@ import (
"time" "time"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
) )
func init() { func init() {

View File

@@ -3,7 +3,7 @@ package v2
import ( import (
"github.com/coreos/etcd/log" "github.com/coreos/etcd/log"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"time" "time"
) )
@@ -13,9 +13,9 @@ func init() {
// Update command // Update command
type UpdateCommand struct { type UpdateCommand struct {
Key string `json:"key"` Key string `json:"key"`
Value string `json:"value"` Value string `json:"value"`
ExpireTime time.Time `json:"expireTime"` ExpireTime time.Time `json:"expireTime"`
} }
// The name of the update command in the log // The name of the update command in the log

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// Create a five nodes // Create a five nodes

View File

@@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// Create a five nodes // Create a five nodes

View File

@@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// remove the node and node rejoin with previous log // remove the node and node rejoin with previous log

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
func TestSimpleMultiNode(t *testing.T) { func TestSimpleMultiNode(t *testing.T) {

View File

@@ -7,7 +7,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// This test creates a single node and then set a value to it to trigger snapshot // This test creates a single node and then set a value to it to trigger snapshot

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// This test creates a single node and then set a value to it. // This test creates a single node and then set a value to it.

View File

@@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
) )
// Create a single node and try to set value // Create a single node and try to set value

View File

@@ -18,7 +18,7 @@ package test
import ( import (
"fmt" "fmt"
"github.com/coreos/go-etcd/etcd" "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"

View File

@@ -6,19 +6,19 @@ import (
"os" "os"
"time" "time"
"github.com/coreos/raft" "github.com/coreos/etcd/third_party/github.com/coreos/raft"
"github.com/coreos/etcd/server" "github.com/coreos/etcd/server"
"github.com/coreos/etcd/store" "github.com/coreos/etcd/store"
) )
const ( const (
testName = "ETCDTEST" testName = "ETCDTEST"
testClientURL = "localhost:4401" testClientURL = "localhost:4401"
testRaftURL = "localhost:7701" testRaftURL = "localhost:7701"
testSnapshotCount = 10000 testSnapshotCount = 10000
testHeartbeatTimeout = time.Duration(50) * time.Millisecond testHeartbeatTimeout = time.Duration(50) * time.Millisecond
testElectionTimeout = time.Duration(200) * time.Millisecond testElectionTimeout = time.Duration(200) * time.Millisecond
) )
// Starts a server in a temporary directory. // Starts a server in a temporary directory.
@@ -33,11 +33,11 @@ func RunServer(f func(*server.Server)) {
followersStats := server.NewRaftFollowersStats(testName) followersStats := server.NewRaftFollowersStats(testName)
psConfig := server.PeerServerConfig{ psConfig := server.PeerServerConfig{
Name: testName, Name: testName,
URL: "http://" + testRaftURL, URL: "http://" + testRaftURL,
Scheme: "http", Scheme: "http",
SnapshotCount: testSnapshotCount, SnapshotCount: testSnapshotCount,
MaxClusterSize: 9, MaxClusterSize: 9,
} }
ps := server.NewPeerServer(psConfig, registry, store, nil, followersStats, serverStats) ps := server.NewPeerServer(psConfig, registry, store, nil, followersStats, serverStats)
psListener, err := server.NewListener(testRaftURL) psListener, err := server.NewListener(testRaftURL)

11
third_party/README vendored
View File

@@ -1,11 +0,0 @@
# Third Party Libraries
The third_party directory has all of the dependencies needed to build
etcd so that we can have a consistent build. `go get` should not be
called at any point during the build process.
## Usage
To update all of the third party libraries call
./update

View File

@@ -44,7 +44,7 @@ import (
"time" "time"
. "./testdata" . "./testdata"
. "code.google.com/p/goprotobuf/proto" . "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
) )
var globalO *Buffer var globalO *Buffer
@@ -507,61 +507,61 @@ func TestReset(t *testing.T) {
func TestEncodeDecode1(t *testing.T) { func TestEncodeDecode1(t *testing.T) {
pb := initGoTest(false) pb := initGoTest(false)
overify(t, pb, overify(t, pb,
"0807"+ // field 1, encoding 0, value 7 "0807"+ // field 1, encoding 0, value 7
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
"5001"+ // field 10, encoding 0, value 1 "5001"+ // field 10, encoding 0, value 1
"5803"+ // field 11, encoding 0, value 3 "5803"+ // field 11, encoding 0, value 3
"6006"+ // field 12, encoding 0, value 6 "6006"+ // field 12, encoding 0, value 6
"6d20000000"+ // field 13, encoding 5, value 0x20 "6d20000000"+ // field 13, encoding 5, value 0x20
"714000000000000000"+ // field 14, encoding 1, value 0x40 "714000000000000000"+ // field 14, encoding 1, value 0x40
"78a019"+ // field 15, encoding 0, value 0xca0 = 3232 "78a019"+ // field 15, encoding 0, value 0xca0 = 3232
"8001c032"+ // field 16, encoding 0, value 0x1940 = 6464 "8001c032"+ // field 16, encoding 0, value 0x1940 = 6464
"8d0100004a45"+ // field 17, encoding 5, value 3232.0 "8d0100004a45"+ // field 17, encoding 5, value 3232.0
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0 "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
"9a0106"+"737472696e67"+ // field 19, encoding 2, string "string" "9a0106"+"737472696e67"+ // field 19, encoding 2, string "string"
"b304"+ // field 70, encoding 3, start group "b304"+ // field 70, encoding 3, start group
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
"b404"+ // field 70, encoding 4, end group "b404"+ // field 70, encoding 4, end group
"aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes" "aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes"
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32 "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
"b8067f") // field 103, encoding 0, 0x7f zigzag64 "b8067f") // field 103, encoding 0, 0x7f zigzag64
} }
// All required fields set, defaults provided. // All required fields set, defaults provided.
func TestEncodeDecode2(t *testing.T) { func TestEncodeDecode2(t *testing.T) {
pb := initGoTest(true) pb := initGoTest(true)
overify(t, pb, overify(t, pb,
"0807"+ // field 1, encoding 0, value 7 "0807"+ // field 1, encoding 0, value 7
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
"5001"+ // field 10, encoding 0, value 1 "5001"+ // field 10, encoding 0, value 1
"5803"+ // field 11, encoding 0, value 3 "5803"+ // field 11, encoding 0, value 3
"6006"+ // field 12, encoding 0, value 6 "6006"+ // field 12, encoding 0, value 6
"6d20000000"+ // field 13, encoding 5, value 32 "6d20000000"+ // field 13, encoding 5, value 32
"714000000000000000"+ // field 14, encoding 1, value 64 "714000000000000000"+ // field 14, encoding 1, value 64
"78a019"+ // field 15, encoding 0, value 3232 "78a019"+ // field 15, encoding 0, value 3232
"8001c032"+ // field 16, encoding 0, value 6464 "8001c032"+ // field 16, encoding 0, value 6464
"8d0100004a45"+ // field 17, encoding 5, value 3232.0 "8d0100004a45"+ // field 17, encoding 5, value 3232.0
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0 "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
"c00201"+ // field 40, encoding 0, value 1 "c00201"+ // field 40, encoding 0, value 1
"c80220"+ // field 41, encoding 0, value 32 "c80220"+ // field 41, encoding 0, value 32
"d00240"+ // field 42, encoding 0, value 64 "d00240"+ // field 42, encoding 0, value 64
"dd0240010000"+ // field 43, encoding 5, value 320 "dd0240010000"+ // field 43, encoding 5, value 320
"e1028002000000000000"+ // field 44, encoding 1, value 640 "e1028002000000000000"+ // field 44, encoding 1, value 640
"e8028019"+ // field 45, encoding 0, value 3200 "e8028019"+ // field 45, encoding 0, value 3200
"f0028032"+ // field 46, encoding 0, value 6400 "f0028032"+ // field 46, encoding 0, value 6400
"fd02e0659948"+ // field 47, encoding 5, value 314159.0 "fd02e0659948"+ // field 47, encoding 5, value 314159.0
"81030000000050971041"+ // field 48, encoding 1, value 271828.0 "81030000000050971041"+ // field 48, encoding 1, value 271828.0
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
"b304"+ // start group field 70 level 1 "b304"+ // start group field 70 level 1
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
"b404"+ // end group field 70 level 1 "b404"+ // end group field 70 level 1
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32 "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64 "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
"90193f"+ // field 402, encoding 0, value 63 "90193f"+ // field 402, encoding 0, value 63
"98197f") // field 403, encoding 0, value 127 "98197f") // field 403, encoding 0, value 127
} }
@@ -583,37 +583,37 @@ func TestEncodeDecode3(t *testing.T) {
pb.F_Sint64Defaulted = Int64(-64) pb.F_Sint64Defaulted = Int64(-64)
overify(t, pb, overify(t, pb,
"0807"+ // field 1, encoding 0, value 7 "0807"+ // field 1, encoding 0, value 7
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
"5001"+ // field 10, encoding 0, value 1 "5001"+ // field 10, encoding 0, value 1
"5803"+ // field 11, encoding 0, value 3 "5803"+ // field 11, encoding 0, value 3
"6006"+ // field 12, encoding 0, value 6 "6006"+ // field 12, encoding 0, value 6
"6d20000000"+ // field 13, encoding 5, value 32 "6d20000000"+ // field 13, encoding 5, value 32
"714000000000000000"+ // field 14, encoding 1, value 64 "714000000000000000"+ // field 14, encoding 1, value 64
"78a019"+ // field 15, encoding 0, value 3232 "78a019"+ // field 15, encoding 0, value 3232
"8001c032"+ // field 16, encoding 0, value 6464 "8001c032"+ // field 16, encoding 0, value 6464
"8d0100004a45"+ // field 17, encoding 5, value 3232.0 "8d0100004a45"+ // field 17, encoding 5, value 3232.0
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0 "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
"c00201"+ // field 40, encoding 0, value 1 "c00201"+ // field 40, encoding 0, value 1
"c80220"+ // field 41, encoding 0, value 32 "c80220"+ // field 41, encoding 0, value 32
"d00240"+ // field 42, encoding 0, value 64 "d00240"+ // field 42, encoding 0, value 64
"dd0240010000"+ // field 43, encoding 5, value 320 "dd0240010000"+ // field 43, encoding 5, value 320
"e1028002000000000000"+ // field 44, encoding 1, value 640 "e1028002000000000000"+ // field 44, encoding 1, value 640
"e8028019"+ // field 45, encoding 0, value 3200 "e8028019"+ // field 45, encoding 0, value 3200
"f0028032"+ // field 46, encoding 0, value 6400 "f0028032"+ // field 46, encoding 0, value 6400
"fd02e0659948"+ // field 47, encoding 5, value 314159.0 "fd02e0659948"+ // field 47, encoding 5, value 314159.0
"81030000000050971041"+ // field 48, encoding 1, value 271828.0 "81030000000050971041"+ // field 48, encoding 1, value 271828.0
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
"b304"+ // start group field 70 level 1 "b304"+ // start group field 70 level 1
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
"b404"+ // end group field 70 level 1 "b404"+ // end group field 70 level 1
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32 "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64 "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
"90193f"+ // field 402, encoding 0, value 63 "90193f"+ // field 402, encoding 0, value 63
"98197f") // field 403, encoding 0, value 127 "98197f") // field 403, encoding 0, value 127
} }
@@ -639,56 +639,56 @@ func TestEncodeDecode4(t *testing.T) {
pb.Optionalgroup = initGoTest_OptionalGroup() pb.Optionalgroup = initGoTest_OptionalGroup()
overify(t, pb, overify(t, pb,
"0807"+ // field 1, encoding 0, value 7 "0807"+ // field 1, encoding 0, value 7
"1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello" "1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello"
"1807"+ // field 3, encoding 0, value 7 "1807"+ // field 3, encoding 0, value 7
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
"320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField) "320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField)
"5001"+ // field 10, encoding 0, value 1 "5001"+ // field 10, encoding 0, value 1
"5803"+ // field 11, encoding 0, value 3 "5803"+ // field 11, encoding 0, value 3
"6006"+ // field 12, encoding 0, value 6 "6006"+ // field 12, encoding 0, value 6
"6d20000000"+ // field 13, encoding 5, value 32 "6d20000000"+ // field 13, encoding 5, value 32
"714000000000000000"+ // field 14, encoding 1, value 64 "714000000000000000"+ // field 14, encoding 1, value 64
"78a019"+ // field 15, encoding 0, value 3232 "78a019"+ // field 15, encoding 0, value 3232
"8001c032"+ // field 16, encoding 0, value 6464 "8001c032"+ // field 16, encoding 0, value 6464
"8d0100004a45"+ // field 17, encoding 5, value 3232.0 "8d0100004a45"+ // field 17, encoding 5, value 3232.0
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0 "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
"f00101"+ // field 30, encoding 0, value 1 "f00101"+ // field 30, encoding 0, value 1
"f80120"+ // field 31, encoding 0, value 32 "f80120"+ // field 31, encoding 0, value 32
"800240"+ // field 32, encoding 0, value 64 "800240"+ // field 32, encoding 0, value 64
"8d02a00c0000"+ // field 33, encoding 5, value 3232 "8d02a00c0000"+ // field 33, encoding 5, value 3232
"91024019000000000000"+ // field 34, encoding 1, value 6464 "91024019000000000000"+ // field 34, encoding 1, value 6464
"9802a0dd13"+ // field 35, encoding 0, value 323232 "9802a0dd13"+ // field 35, encoding 0, value 323232
"a002c0ba27"+ // field 36, encoding 0, value 646464 "a002c0ba27"+ // field 36, encoding 0, value 646464
"ad0200000042"+ // field 37, encoding 5, value 32.0 "ad0200000042"+ // field 37, encoding 5, value 32.0
"b1020000000000005040"+ // field 38, encoding 1, value 64.0 "b1020000000000005040"+ // field 38, encoding 1, value 64.0
"ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello" "ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello"
"c00201"+ // field 40, encoding 0, value 1 "c00201"+ // field 40, encoding 0, value 1
"c80220"+ // field 41, encoding 0, value 32 "c80220"+ // field 41, encoding 0, value 32
"d00240"+ // field 42, encoding 0, value 64 "d00240"+ // field 42, encoding 0, value 64
"dd0240010000"+ // field 43, encoding 5, value 320 "dd0240010000"+ // field 43, encoding 5, value 320
"e1028002000000000000"+ // field 44, encoding 1, value 640 "e1028002000000000000"+ // field 44, encoding 1, value 640
"e8028019"+ // field 45, encoding 0, value 3200 "e8028019"+ // field 45, encoding 0, value 3200
"f0028032"+ // field 46, encoding 0, value 6400 "f0028032"+ // field 46, encoding 0, value 6400
"fd02e0659948"+ // field 47, encoding 5, value 314159.0 "fd02e0659948"+ // field 47, encoding 5, value 314159.0
"81030000000050971041"+ // field 48, encoding 1, value 271828.0 "81030000000050971041"+ // field 48, encoding 1, value 271828.0
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
"b304"+ // start group field 70 level 1 "b304"+ // start group field 70 level 1
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
"b404"+ // end group field 70 level 1 "b404"+ // end group field 70 level 1
"d305"+ // start group field 90 level 1 "d305"+ // start group field 90 level 1
"da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional" "da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional"
"d405"+ // end group field 90 level 1 "d405"+ // end group field 90 level 1
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32 "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64 "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
"ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose" "ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose"
"f0123f"+ // field 302, encoding 0, value 63 "f0123f"+ // field 302, encoding 0, value 63
"f8127f"+ // field 303, encoding 0, value 127 "f8127f"+ // field 303, encoding 0, value 127
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
"90193f"+ // field 402, encoding 0, value 63 "90193f"+ // field 402, encoding 0, value 63
"98197f") // field 403, encoding 0, value 127 "98197f") // field 403, encoding 0, value 127
} }
@@ -712,71 +712,71 @@ func TestEncodeDecode5(t *testing.T) {
pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()} pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()}
overify(t, pb, overify(t, pb,
"0807"+ // field 1, encoding 0, value 7 "0807"+ // field 1, encoding 0, value 7
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
"2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
"2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField) "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
"5001"+ // field 10, encoding 0, value 1 "5001"+ // field 10, encoding 0, value 1
"5803"+ // field 11, encoding 0, value 3 "5803"+ // field 11, encoding 0, value 3
"6006"+ // field 12, encoding 0, value 6 "6006"+ // field 12, encoding 0, value 6
"6d20000000"+ // field 13, encoding 5, value 32 "6d20000000"+ // field 13, encoding 5, value 32
"714000000000000000"+ // field 14, encoding 1, value 64 "714000000000000000"+ // field 14, encoding 1, value 64
"78a019"+ // field 15, encoding 0, value 3232 "78a019"+ // field 15, encoding 0, value 3232
"8001c032"+ // field 16, encoding 0, value 6464 "8001c032"+ // field 16, encoding 0, value 6464
"8d0100004a45"+ // field 17, encoding 5, value 3232.0 "8d0100004a45"+ // field 17, encoding 5, value 3232.0
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0 "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
"a00100"+ // field 20, encoding 0, value 0 "a00100"+ // field 20, encoding 0, value 0
"a00101"+ // field 20, encoding 0, value 1 "a00101"+ // field 20, encoding 0, value 1
"a80120"+ // field 21, encoding 0, value 32 "a80120"+ // field 21, encoding 0, value 32
"a80121"+ // field 21, encoding 0, value 33 "a80121"+ // field 21, encoding 0, value 33
"b00140"+ // field 22, encoding 0, value 64 "b00140"+ // field 22, encoding 0, value 64
"b00141"+ // field 22, encoding 0, value 65 "b00141"+ // field 22, encoding 0, value 65
"bd01a00c0000"+ // field 23, encoding 5, value 3232 "bd01a00c0000"+ // field 23, encoding 5, value 3232
"bd01050d0000"+ // field 23, encoding 5, value 3333 "bd01050d0000"+ // field 23, encoding 5, value 3333
"c1014019000000000000"+ // field 24, encoding 1, value 6464 "c1014019000000000000"+ // field 24, encoding 1, value 6464
"c101a519000000000000"+ // field 24, encoding 1, value 6565 "c101a519000000000000"+ // field 24, encoding 1, value 6565
"c801a0dd13"+ // field 25, encoding 0, value 323232 "c801a0dd13"+ // field 25, encoding 0, value 323232
"c80195ac14"+ // field 25, encoding 0, value 333333 "c80195ac14"+ // field 25, encoding 0, value 333333
"d001c0ba27"+ // field 26, encoding 0, value 646464 "d001c0ba27"+ // field 26, encoding 0, value 646464
"d001b58928"+ // field 26, encoding 0, value 656565 "d001b58928"+ // field 26, encoding 0, value 656565
"dd0100000042"+ // field 27, encoding 5, value 32.0 "dd0100000042"+ // field 27, encoding 5, value 32.0
"dd0100000442"+ // field 27, encoding 5, value 33.0 "dd0100000442"+ // field 27, encoding 5, value 33.0
"e1010000000000005040"+ // field 28, encoding 1, value 64.0 "e1010000000000005040"+ // field 28, encoding 1, value 64.0
"e1010000000000405040"+ // field 28, encoding 1, value 65.0 "e1010000000000405040"+ // field 28, encoding 1, value 65.0
"ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello" "ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello"
"ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor" "ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor"
"c00201"+ // field 40, encoding 0, value 1 "c00201"+ // field 40, encoding 0, value 1
"c80220"+ // field 41, encoding 0, value 32 "c80220"+ // field 41, encoding 0, value 32
"d00240"+ // field 42, encoding 0, value 64 "d00240"+ // field 42, encoding 0, value 64
"dd0240010000"+ // field 43, encoding 5, value 320 "dd0240010000"+ // field 43, encoding 5, value 320
"e1028002000000000000"+ // field 44, encoding 1, value 640 "e1028002000000000000"+ // field 44, encoding 1, value 640
"e8028019"+ // field 45, encoding 0, value 3200 "e8028019"+ // field 45, encoding 0, value 3200
"f0028032"+ // field 46, encoding 0, value 6400 "f0028032"+ // field 46, encoding 0, value 6400
"fd02e0659948"+ // field 47, encoding 5, value 314159.0 "fd02e0659948"+ // field 47, encoding 5, value 314159.0
"81030000000050971041"+ // field 48, encoding 1, value 271828.0 "81030000000050971041"+ // field 48, encoding 1, value 271828.0
"8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n" "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
"b304"+ // start group field 70 level 1 "b304"+ // start group field 70 level 1
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
"b404"+ // end group field 70 level 1 "b404"+ // end group field 70 level 1
"8305"+ // start group field 80 level 1 "8305"+ // start group field 80 level 1
"8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
"8405"+ // end group field 80 level 1 "8405"+ // end group field 80 level 1
"8305"+ // start group field 80 level 1 "8305"+ // start group field 80 level 1
"8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated" "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
"8405"+ // end group field 80 level 1 "8405"+ // end group field 80 level 1
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32 "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64 "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
"ca0c03"+"626967"+ // field 201, encoding 2, string "big" "ca0c03"+"626967"+ // field 201, encoding 2, string "big"
"ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose" "ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose"
"d00c40"+ // field 202, encoding 0, value 32 "d00c40"+ // field 202, encoding 0, value 32
"d00c3f"+ // field 202, encoding 0, value -32 "d00c3f"+ // field 202, encoding 0, value -32
"d80c8001"+ // field 203, encoding 0, value 64 "d80c8001"+ // field 203, encoding 0, value 64
"d80c7f"+ // field 203, encoding 0, value -64 "d80c7f"+ // field 203, encoding 0, value -64
"8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose" "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
"90193f"+ // field 402, encoding 0, value 63 "90193f"+ // field 402, encoding 0, value 63
"98197f") // field 403, encoding 0, value 127 "98197f") // field 403, encoding 0, value 127
} }
@@ -796,43 +796,43 @@ func TestEncodeDecode6(t *testing.T) {
pb.F_Sint64RepeatedPacked = []int64{64, -64} pb.F_Sint64RepeatedPacked = []int64{64, -64}
overify(t, pb, overify(t, pb,
"0807"+ // field 1, encoding 0, value 7 "0807"+ // field 1, encoding 0, value 7
"220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField) "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
"5001"+ // field 10, encoding 0, value 1 "5001"+ // field 10, encoding 0, value 1
"5803"+ // field 11, encoding 0, value 3 "5803"+ // field 11, encoding 0, value 3
"6006"+ // field 12, encoding 0, value 6 "6006"+ // field 12, encoding 0, value 6
"6d20000000"+ // field 13, encoding 5, value 32 "6d20000000"+ // field 13, encoding 5, value 32
"714000000000000000"+ // field 14, encoding 1, value 64 "714000000000000000"+ // field 14, encoding 1, value 64
"78a019"+ // field 15, encoding 0, value 3232 "78a019"+ // field 15, encoding 0, value 3232
"8001c032"+ // field 16, encoding 0, value 6464 "8001c032"+ // field 16, encoding 0, value 6464
"8d0100004a45"+ // field 17, encoding 5, value 3232.0 "8d0100004a45"+ // field 17, encoding 5, value 3232.0
"9101000000000040b940"+ // field 18, encoding 1, value 6464.0 "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
"9a0106"+"737472696e67"+ // field 19, encoding 2 string "string" "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
"9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1 "9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1
"9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33 "9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33
"a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65 "a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65
"aa0308"+ // field 53, encoding 2, 8 bytes "aa0308"+ // field 53, encoding 2, 8 bytes
"a00c0000050d0000"+ // value 3232, value 3333 "a00c0000050d0000"+ // value 3232, value 3333
"b20310"+ // field 54, encoding 2, 16 bytes "b20310"+ // field 54, encoding 2, 16 bytes
"4019000000000000a519000000000000"+ // value 6464, value 6565 "4019000000000000a519000000000000"+ // value 6464, value 6565
"ba0306"+ // field 55, encoding 2, 6 bytes "ba0306"+ // field 55, encoding 2, 6 bytes
"a0dd1395ac14"+ // value 323232, value 333333 "a0dd1395ac14"+ // value 323232, value 333333
"c20306"+ // field 56, encoding 2, 6 bytes "c20306"+ // field 56, encoding 2, 6 bytes
"c0ba27b58928"+ // value 646464, value 656565 "c0ba27b58928"+ // value 646464, value 656565
"ca0308"+ // field 57, encoding 2, 8 bytes "ca0308"+ // field 57, encoding 2, 8 bytes
"0000004200000442"+ // value 32.0, value 33.0 "0000004200000442"+ // value 32.0, value 33.0
"d20310"+ // field 58, encoding 2, 16 bytes "d20310"+ // field 58, encoding 2, 16 bytes
"00000000000050400000000000405040"+ // value 64.0, value 65.0 "00000000000050400000000000405040"+ // value 64.0, value 65.0
"b304"+ // start group field 70 level 1 "b304"+ // start group field 70 level 1
"ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required" "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
"b404"+ // end group field 70 level 1 "b404"+ // end group field 70 level 1
"aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes" "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
"b0063f"+ // field 102, encoding 0, 0x3f zigzag32 "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
"b8067f"+ // field 103, encoding 0, 0x7f zigzag64 "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
"b21f02"+ // field 502, encoding 2, 2 bytes "b21f02"+ // field 502, encoding 2, 2 bytes
"403f"+ // value 32, value -32 "403f"+ // value 32, value -32
"ba1f03"+ // field 503, encoding 2, 3 bytes "ba1f03"+ // field 503, encoding 2, 3 bytes
"80017f") // value 64, value -64 "80017f") // value 64, value -64
} }
// Test that we can encode empty bytes fields. // Test that we can encode empty bytes fields.
@@ -898,13 +898,13 @@ func TestSkippingUnrecognizedFields(t *testing.T) {
// Now new a GoSkipTest record. // Now new a GoSkipTest record.
skip := &GoSkipTest{ skip := &GoSkipTest{
SkipInt32: Int32(32), SkipInt32: Int32(32),
SkipFixed32: Uint32(3232), SkipFixed32: Uint32(3232),
SkipFixed64: Uint64(6464), SkipFixed64: Uint64(6464),
SkipString: String("skipper"), SkipString: String("skipper"),
Skipgroup: &GoSkipTest_SkipGroup{ Skipgroup: &GoSkipTest_SkipGroup{
GroupInt32: Int32(75), GroupInt32: Int32(75),
GroupString: String("wxyz"), GroupString: String("wxyz"),
}, },
} }
@@ -944,8 +944,8 @@ func TestSkippingUnrecognizedFields(t *testing.T) {
func TestSubmessageUnrecognizedFields(t *testing.T) { func TestSubmessageUnrecognizedFields(t *testing.T) {
nm := &NewMessage{ nm := &NewMessage{
Nested: &NewMessage_Nested{ Nested: &NewMessage_Nested{
Name: String("Nigel"), Name: String("Nigel"),
FoodGroup: String("carbs"), FoodGroup: String("carbs"),
}, },
} }
b, err := Marshal(nm) b, err := Marshal(nm)
@@ -960,9 +960,9 @@ func TestSubmessageUnrecognizedFields(t *testing.T) {
} }
exp := &OldMessage{ exp := &OldMessage{
Nested: &OldMessage_Nested{ Nested: &OldMessage_Nested{
Name: String("Nigel"), Name: String("Nigel"),
// normal protocol buffer users should not do this // normal protocol buffer users should not do this
XXX_unrecognized: []byte("\x12\x05carbs"), XXX_unrecognized: []byte("\x12\x05carbs"),
}, },
} }
if !Equal(om, exp) { if !Equal(om, exp) {
@@ -999,7 +999,7 @@ func TestBigRepeated(t *testing.T) {
pb := initGoTest(true) pb := initGoTest(true)
// Create the arrays // Create the arrays
const N = 50 // Internally the library starts much smaller. const N = 50 // Internally the library starts much smaller.
pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N) pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N)
pb.F_Sint64Repeated = make([]int64, N) pb.F_Sint64Repeated = make([]int64, N)
pb.F_Sint32Repeated = make([]int32, N) pb.F_Sint32Repeated = make([]int32, N)
@@ -1047,7 +1047,7 @@ func TestBigRepeated(t *testing.T) {
// Check the checkable values // Check the checkable values
for i := uint64(0); i < N; i++ { for i := uint64(0); i < N; i++ {
if pbd.Repeatedgroup[i] == nil { // TODO: more checking? if pbd.Repeatedgroup[i] == nil { // TODO: more checking?
t.Error("pbd.Repeatedgroup bad") t.Error("pbd.Repeatedgroup bad")
} }
var x uint64 var x uint64
@@ -1099,7 +1099,7 @@ func TestBigRepeated(t *testing.T) {
if pbd.F_BoolRepeated[i] != (i%2 == 0) { if pbd.F_BoolRepeated[i] != (i%2 == 0) {
t.Error("pbd.F_BoolRepeated bad", x, i) t.Error("pbd.F_BoolRepeated bad", x, i)
} }
if pbd.RepeatedField[i] == nil { // TODO: more checking? if pbd.RepeatedField[i] == nil { // TODO: more checking?
t.Error("pbd.RepeatedField bad") t.Error("pbd.RepeatedField bad")
} }
} }
@@ -1159,8 +1159,8 @@ func TestProto1RepeatedGroup(t *testing.T) {
pb := &MessageList{ pb := &MessageList{
Message: []*MessageList_Message{ Message: []*MessageList_Message{
{ {
Name: String("blah"), Name: String("blah"),
Count: Int32(7), Count: Int32(7),
}, },
// NOTE: pb.Message[1] is a nil // NOTE: pb.Message[1] is a nil
nil, nil,
@@ -1240,9 +1240,9 @@ type NNIMessage struct {
nni nonNillableInt nni nonNillableInt
} }
func (*NNIMessage) Reset() {} func (*NNIMessage) Reset() {}
func (*NNIMessage) String() string { return "" } func (*NNIMessage) String() string { return "" }
func (*NNIMessage) ProtoMessage() {} func (*NNIMessage) ProtoMessage() {}
// A type that implements the Marshaler interface and is nillable. // A type that implements the Marshaler interface and is nillable.
type nillableMessage struct { type nillableMessage struct {
@@ -1257,9 +1257,9 @@ type NMMessage struct {
nm *nillableMessage nm *nillableMessage
} }
func (*NMMessage) Reset() {} func (*NMMessage) Reset() {}
func (*NMMessage) String() string { return "" } func (*NMMessage) String() string { return "" }
func (*NMMessage) ProtoMessage() {} func (*NMMessage) ProtoMessage() {}
// Verify a type that uses the Marshaler interface, but has a nil pointer. // Verify a type that uses the Marshaler interface, but has a nil pointer.
func TestNilMarshaler(t *testing.T) { func TestNilMarshaler(t *testing.T) {
@@ -1273,7 +1273,7 @@ func TestNilMarshaler(t *testing.T) {
// Try a struct with a Marshaler field that is not nillable. // Try a struct with a Marshaler field that is not nillable.
nnim := new(NNIMessage) nnim := new(NNIMessage)
nnim.nni = 7 nnim.nni = 7
var _ Marshaler = nnim.nni // verify it is truly a Marshaler var _ Marshaler = nnim.nni // verify it is truly a Marshaler
if _, err := Marshal(nnim); err != nil { if _, err := Marshal(nnim); err != nil {
t.Error("unexpected error marshaling nnim: ", err) t.Error("unexpected error marshaling nnim: ", err)
} }
@@ -1286,23 +1286,23 @@ func TestAllSetDefaults(t *testing.T) {
F_Nan: Float32(1.7), F_Nan: Float32(1.7),
} }
expected := &Defaults{ expected := &Defaults{
F_Bool: Bool(true), F_Bool: Bool(true),
F_Int32: Int32(32), F_Int32: Int32(32),
F_Int64: Int64(64), F_Int64: Int64(64),
F_Fixed32: Uint32(320), F_Fixed32: Uint32(320),
F_Fixed64: Uint64(640), F_Fixed64: Uint64(640),
F_Uint32: Uint32(3200), F_Uint32: Uint32(3200),
F_Uint64: Uint64(6400), F_Uint64: Uint64(6400),
F_Float: Float32(314159), F_Float: Float32(314159),
F_Double: Float64(271828), F_Double: Float64(271828),
F_String: String(`hello, "world!"` + "\n"), F_String: String(`hello, "world!"` + "\n"),
F_Bytes: []byte("Bignose"), F_Bytes: []byte("Bignose"),
F_Sint32: Int32(-32), F_Sint32: Int32(-32),
F_Sint64: Int64(-64), F_Sint64: Int64(-64),
F_Enum: Defaults_GREEN.Enum(), F_Enum: Defaults_GREEN.Enum(),
F_Pinf: Float32(float32(math.Inf(1))), F_Pinf: Float32(float32(math.Inf(1))),
F_Ninf: Float32(float32(math.Inf(-1))), F_Ninf: Float32(float32(math.Inf(-1))),
F_Nan: Float32(1.7), F_Nan: Float32(1.7),
} }
SetDefaults(m) SetDefaults(m)
if !Equal(m, expected) { if !Equal(m, expected) {
@@ -1323,16 +1323,16 @@ func TestSetDefaultsWithSetField(t *testing.T) {
func TestSetDefaultsWithSubMessage(t *testing.T) { func TestSetDefaultsWithSubMessage(t *testing.T) {
m := &OtherMessage{ m := &OtherMessage{
Key: Int64(123), Key: Int64(123),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("gopher"), Host: String("gopher"),
}, },
} }
expected := &OtherMessage{ expected := &OtherMessage{
Key: Int64(123), Key: Int64(123),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("gopher"), Host: String("gopher"),
Port: Int32(4000), Port: Int32(4000),
}, },
} }
SetDefaults(m) SetDefaults(m)
@@ -1375,12 +1375,12 @@ func TestMaximumTagNumber(t *testing.T) {
func TestJSON(t *testing.T) { func TestJSON(t *testing.T) {
m := &MyMessage{ m := &MyMessage{
Count: Int32(4), Count: Int32(4),
Pet: []string{"bunny", "kitty"}, Pet: []string{"bunny", "kitty"},
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("cauchy"), Host: String("cauchy"),
}, },
Bikeshed: MyMessage_GREEN.Enum(), Bikeshed: MyMessage_GREEN.Enum(),
} }
const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}` const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}`
@@ -1413,7 +1413,7 @@ func TestJSON(t *testing.T) {
} }
func TestBadWireType(t *testing.T) { func TestBadWireType(t *testing.T) {
b := []byte{7<<3 | 6} // field 7, wire type 6 b := []byte{7<<3 | 6} // field 7, wire type 6
pb := new(OtherMessage) pb := new(OtherMessage)
if err := Unmarshal(b, pb); err == nil { if err := Unmarshal(b, pb); err == nil {
t.Errorf("Unmarshal did not fail") t.Errorf("Unmarshal did not fail")
@@ -1610,10 +1610,10 @@ func TestUnmarshalMergesMessages(t *testing.T) {
// If a nested message occurs twice in the input, // If a nested message occurs twice in the input,
// the fields should be merged when decoding. // the fields should be merged when decoding.
a := &OtherMessage{ a := &OtherMessage{
Key: Int64(123), Key: Int64(123),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("polhode"), Host: String("polhode"),
Port: Int32(1234), Port: Int32(1234),
}, },
} }
aData, err := Marshal(a) aData, err := Marshal(a)
@@ -1621,10 +1621,10 @@ func TestUnmarshalMergesMessages(t *testing.T) {
t.Fatalf("Marshal(a): %v", err) t.Fatalf("Marshal(a): %v", err)
} }
b := &OtherMessage{ b := &OtherMessage{
Weight: Float32(1.2), Weight: Float32(1.2),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("herpolhode"), Host: String("herpolhode"),
Connected: Bool(true), Connected: Bool(true),
}, },
} }
bData, err := Marshal(b) bData, err := Marshal(b)
@@ -1632,12 +1632,12 @@ func TestUnmarshalMergesMessages(t *testing.T) {
t.Fatalf("Marshal(b): %v", err) t.Fatalf("Marshal(b): %v", err)
} }
want := &OtherMessage{ want := &OtherMessage{
Key: Int64(123), Key: Int64(123),
Weight: Float32(1.2), Weight: Float32(1.2),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("herpolhode"), Host: String("herpolhode"),
Port: Int32(1234), Port: Int32(1234),
Connected: Bool(true), Connected: Bool(true),
}, },
} }
got := new(OtherMessage) got := new(OtherMessage)
@@ -1651,8 +1651,8 @@ func TestUnmarshalMergesMessages(t *testing.T) {
func TestEncodingSizes(t *testing.T) { func TestEncodingSizes(t *testing.T) {
tests := []struct { tests := []struct {
m Message m Message
n int n int
}{ }{
{&Defaults{F_Int32: Int32(math.MaxInt32)}, 6}, {&Defaults{F_Int32: Int32(math.MaxInt32)}, 6},
{&Defaults{F_Int32: Int32(math.MinInt32)}, 6}, {&Defaults{F_Int32: Int32(math.MinInt32)}, 6},
@@ -1676,22 +1676,22 @@ func TestRequiredNotSetError(t *testing.T) {
pb.F_Int32Required = nil pb.F_Int32Required = nil
pb.F_Int64Required = nil pb.F_Int64Required = nil
expected := "0807" + // field 1, encoding 0, value 7 expected := "0807" + // field 1, encoding 0, value 7
"2206" + "120474797065" + // field 4, encoding 2 (GoTestField) "2206" + "120474797065" + // field 4, encoding 2 (GoTestField)
"5001" + // field 10, encoding 0, value 1 "5001" + // field 10, encoding 0, value 1
"6d20000000" + // field 13, encoding 5, value 0x20 "6d20000000" + // field 13, encoding 5, value 0x20
"714000000000000000" + // field 14, encoding 1, value 0x40 "714000000000000000" + // field 14, encoding 1, value 0x40
"78a019" + // field 15, encoding 0, value 0xca0 = 3232 "78a019" + // field 15, encoding 0, value 0xca0 = 3232
"8001c032" + // field 16, encoding 0, value 0x1940 = 6464 "8001c032" + // field 16, encoding 0, value 0x1940 = 6464
"8d0100004a45" + // field 17, encoding 5, value 3232.0 "8d0100004a45" + // field 17, encoding 5, value 3232.0
"9101000000000040b940" + // field 18, encoding 1, value 6464.0 "9101000000000040b940" + // field 18, encoding 1, value 6464.0
"9a0106" + "737472696e67" + // field 19, encoding 2, string "string" "9a0106" + "737472696e67" + // field 19, encoding 2, string "string"
"b304" + // field 70, encoding 3, start group "b304" + // field 70, encoding 3, start group
"ba0408" + "7265717569726564" + // field 71, encoding 2, string "required" "ba0408" + "7265717569726564" + // field 71, encoding 2, string "required"
"b404" + // field 70, encoding 4, end group "b404" + // field 70, encoding 4, end group
"aa0605" + "6279746573" + // field 101, encoding 2, string "bytes" "aa0605" + "6279746573" + // field 101, encoding 2, string "bytes"
"b0063f" + // field 102, encoding 0, 0x3f zigzag32 "b0063f" + // field 102, encoding 0, 0x3f zigzag32
"b8067f" // field 103, encoding 0, 0x7f zigzag64 "b8067f" // field 103, encoding 0, 0x7f zigzag64
o := old() o := old()
bytes, err := Marshal(pb) bytes, err := Marshal(pb)
@@ -1751,7 +1751,7 @@ func fuzzUnmarshal(t *testing.T, data []byte) {
func testMsg() *GoTest { func testMsg() *GoTest {
pb := initGoTest(true) pb := initGoTest(true)
const N = 1000 // Internally the library starts much smaller. const N = 1000 // Internally the library starts much smaller.
pb.F_Int32Repeated = make([]int32, N) pb.F_Int32Repeated = make([]int32, N)
pb.F_DoubleRepeated = make([]float64, N) pb.F_DoubleRepeated = make([]float64, N)
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
@@ -1869,13 +1869,13 @@ func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) {
b.StopTimer() b.StopTimer()
pb := initGoTestField() pb := initGoTestField()
skip := &GoSkipTest{ skip := &GoSkipTest{
SkipInt32: Int32(32), SkipInt32: Int32(32),
SkipFixed32: Uint32(3232), SkipFixed32: Uint32(3232),
SkipFixed64: Uint64(6464), SkipFixed64: Uint64(6464),
SkipString: String("skipper"), SkipString: String("skipper"),
Skipgroup: &GoSkipTest_SkipGroup{ Skipgroup: &GoSkipTest_SkipGroup{
GroupInt32: Int32(75), GroupInt32: Int32(75),
GroupString: String("wxyz"), GroupString: String("wxyz"),
}, },
} }

View File

@@ -34,19 +34,19 @@ package proto_test
import ( import (
"testing" "testing"
"code.google.com/p/goprotobuf/proto" "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
pb "./testdata" pb "./testdata"
) )
var cloneTestMessage = &pb.MyMessage{ var cloneTestMessage = &pb.MyMessage{
Count: proto.Int32(42), Count: proto.Int32(42),
Name: proto.String("Dave"), Name: proto.String("Dave"),
Pet: []string{"bunny", "kitty", "horsey"}, Pet: []string{"bunny", "kitty", "horsey"},
Inner: &pb.InnerMessage{ Inner: &pb.InnerMessage{
Host: proto.String("niles"), Host: proto.String("niles"),
Port: proto.Int32(9099), Port: proto.Int32(9099),
Connected: proto.Bool(true), Connected: proto.Bool(true),
}, },
Others: []*pb.OtherMessage{ Others: []*pb.OtherMessage{
{ {
@@ -56,7 +56,7 @@ var cloneTestMessage = &pb.MyMessage{
Somegroup: &pb.MyMessage_SomeGroup{ Somegroup: &pb.MyMessage_SomeGroup{
GroupField: proto.Int32(6), GroupField: proto.Int32(6),
}, },
RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
} }
func init() { func init() {
@@ -99,17 +99,17 @@ var mergeTests = []struct {
Name: proto.String("Dave"), Name: proto.String("Dave"),
}, },
want: &pb.MyMessage{ want: &pb.MyMessage{
Count: proto.Int32(42), Count: proto.Int32(42),
Name: proto.String("Dave"), Name: proto.String("Dave"),
}, },
}, },
{ {
src: &pb.MyMessage{ src: &pb.MyMessage{
Inner: &pb.InnerMessage{ Inner: &pb.InnerMessage{
Host: proto.String("hey"), Host: proto.String("hey"),
Connected: proto.Bool(true), Connected: proto.Bool(true),
}, },
Pet: []string{"horsey"}, Pet: []string{"horsey"},
Others: []*pb.OtherMessage{ Others: []*pb.OtherMessage{
{ {
Value: []byte("some bytes"), Value: []byte("some bytes"),
@@ -118,10 +118,10 @@ var mergeTests = []struct {
}, },
dst: &pb.MyMessage{ dst: &pb.MyMessage{
Inner: &pb.InnerMessage{ Inner: &pb.InnerMessage{
Host: proto.String("niles"), Host: proto.String("niles"),
Port: proto.Int32(9099), Port: proto.Int32(9099),
}, },
Pet: []string{"bunny", "kitty"}, Pet: []string{"bunny", "kitty"},
Others: []*pb.OtherMessage{ Others: []*pb.OtherMessage{
{ {
Key: proto.Int64(31415926535), Key: proto.Int64(31415926535),
@@ -134,11 +134,11 @@ var mergeTests = []struct {
}, },
want: &pb.MyMessage{ want: &pb.MyMessage{
Inner: &pb.InnerMessage{ Inner: &pb.InnerMessage{
Host: proto.String("hey"), Host: proto.String("hey"),
Connected: proto.Bool(true), Connected: proto.Bool(true),
Port: proto.Int32(9099), Port: proto.Int32(9099),
}, },
Pet: []string{"bunny", "kitty", "horsey"}, Pet: []string{"bunny", "kitty", "horsey"},
Others: []*pb.OtherMessage{ Others: []*pb.OtherMessage{
{ {
Key: proto.Int64(31415926535), Key: proto.Int64(31415926535),
@@ -158,13 +158,13 @@ var mergeTests = []struct {
Somegroup: &pb.MyMessage_SomeGroup{ Somegroup: &pb.MyMessage_SomeGroup{
GroupField: proto.Int32(6), GroupField: proto.Int32(6),
}, },
RepBytes: [][]byte{[]byte("sham")}, RepBytes: [][]byte{[]byte("sham")},
}, },
want: &pb.MyMessage{ want: &pb.MyMessage{
Somegroup: &pb.MyMessage_SomeGroup{ Somegroup: &pb.MyMessage_SomeGroup{
GroupField: proto.Int32(6), GroupField: proto.Int32(6),
}, },
RepBytes: [][]byte{[]byte("sham"), []byte("wow")}, RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
}, },
}, },
} }

View File

@@ -35,7 +35,7 @@ import (
"testing" "testing"
pb "./testdata" pb "./testdata"
. "code.google.com/p/goprotobuf/proto" . "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
) )
// Four identical base messages. // Four identical base messages.
@@ -85,9 +85,9 @@ func init() {
} }
var EqualTests = []struct { var EqualTests = []struct {
desc string desc string
a, b Message a, b Message
exp bool exp bool
}{ }{
{"different types", &pb.GoEnum{}, &pb.GoTestField{}, false}, {"different types", &pb.GoEnum{}, &pb.GoTestField{}, false},
{"equal empty", &pb.GoEnum{}, &pb.GoEnum{}, true}, {"equal empty", &pb.GoEnum{}, &pb.GoEnum{}, true},
@@ -142,13 +142,13 @@ var EqualTests = []struct {
{ {
"message with group", "message with group",
&pb.MyMessage{ &pb.MyMessage{
Count: Int32(1), Count: Int32(1),
Somegroup: &pb.MyMessage_SomeGroup{ Somegroup: &pb.MyMessage_SomeGroup{
GroupField: Int32(5), GroupField: Int32(5),
}, },
}, },
&pb.MyMessage{ &pb.MyMessage{
Count: Int32(1), Count: Int32(1),
Somegroup: &pb.MyMessage_SomeGroup{ Somegroup: &pb.MyMessage_SomeGroup{
GroupField: Int32(5), GroupField: Int32(5),
}, },

View File

@@ -36,7 +36,7 @@ import (
"testing" "testing"
pb "./testdata" pb "./testdata"
. "code.google.com/p/goprotobuf/proto" . "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
) )
var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)} var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)}
@@ -58,8 +58,8 @@ func init() {
} }
var SizeTests = []struct { var SizeTests = []struct {
desc string desc string
pb Message pb Message
}{ }{
{"empty", &pb.OtherMessage{}}, {"empty", &pb.OtherMessage{}},
// Basic types. // Basic types.

File diff suppressed because it is too large Load Diff

View File

@@ -37,13 +37,13 @@ import (
"testing" "testing"
. "./testdata" . "./testdata"
. "code.google.com/p/goprotobuf/proto" . "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
) )
type UnmarshalTextTest struct { type UnmarshalTextTest struct {
in string in string
err string // if "", no error expected err string // if "", no error expected
out *MyMessage out *MyMessage
} }
func buildExtStructTest(text string) UnmarshalTextTest { func buildExtStructTest(text string) UnmarshalTextTest {
@@ -78,97 +78,97 @@ func buildExtRepStringTest(text string) UnmarshalTextTest {
var unMarshalTextTests = []UnmarshalTextTest{ var unMarshalTextTests = []UnmarshalTextTest{
// Basic // Basic
{ {
in: " count:42\n name:\"Dave\" ", in: " count:42\n name:\"Dave\" ",
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String("Dave"), Name: String("Dave"),
}, },
}, },
// Empty quoted string // Empty quoted string
{ {
in: `count:42 name:""`, in: `count:42 name:""`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String(""), Name: String(""),
}, },
}, },
// Quoted string concatenation // Quoted string concatenation
{ {
in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`, in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String("My name is elsewhere"), Name: String("My name is elsewhere"),
}, },
}, },
// Quoted string with escaped apostrophe // Quoted string with escaped apostrophe
{ {
in: `count:42 name: "HOLIDAY - New Year\'s Day"`, in: `count:42 name: "HOLIDAY - New Year\'s Day"`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String("HOLIDAY - New Year's Day"), Name: String("HOLIDAY - New Year's Day"),
}, },
}, },
// Quoted string with single quote // Quoted string with single quote
{ {
in: `count:42 name: 'Roger "The Ramster" Ramjet'`, in: `count:42 name: 'Roger "The Ramster" Ramjet'`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String(`Roger "The Ramster" Ramjet`), Name: String(`Roger "The Ramster" Ramjet`),
}, },
}, },
// Quoted string with all the accepted special characters from the C++ test // 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\"", in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"",
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"), Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"),
}, },
}, },
// Quoted string with quoted backslash // Quoted string with quoted backslash
{ {
in: `count:42 name: "\\'xyz"`, in: `count:42 name: "\\'xyz"`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String(`\'xyz`), Name: String(`\'xyz`),
}, },
}, },
// Quoted string with UTF-8 bytes. // Quoted string with UTF-8 bytes.
{ {
in: "count:42 name: '\303\277\302\201\xAB'", in: "count:42 name: '\303\277\302\201\xAB'",
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String("\303\277\302\201\xAB"), Name: String("\303\277\302\201\xAB"),
}, },
}, },
// Bad quoted string // Bad quoted string
{ {
in: `inner: < host: "\0" >` + "\n", in: `inner: < host: "\0" >` + "\n",
err: `line 1.15: invalid quoted string "\0"`, err: `line 1.15: invalid quoted string "\0"`,
}, },
// Number too large for int64 // Number too large for int64
{ {
in: "count: 123456789012345678901", in: "count: 123456789012345678901",
err: "line 1.7: invalid int32: 123456789012345678901", err: "line 1.7: invalid int32: 123456789012345678901",
}, },
// Number too large for int32 // Number too large for int32
{ {
in: "count: 1234567890123", in: "count: 1234567890123",
err: "line 1.7: invalid int32: 1234567890123", err: "line 1.7: invalid int32: 1234567890123",
}, },
// Number in hexadecimal // Number in hexadecimal
{ {
in: "count: 0x2beef", in: "count: 0x2beef",
out: &MyMessage{ out: &MyMessage{
Count: Int32(0x2beef), Count: Int32(0x2beef),
}, },
@@ -176,7 +176,7 @@ var unMarshalTextTests = []UnmarshalTextTest{
// Number in octal // Number in octal
{ {
in: "count: 024601", in: "count: 024601",
out: &MyMessage{ out: &MyMessage{
Count: Int32(024601), Count: Int32(024601),
}, },
@@ -184,9 +184,9 @@ var unMarshalTextTests = []UnmarshalTextTest{
// Floating point number with "f" suffix // Floating point number with "f" suffix
{ {
in: "count: 4 others:< weight: 17.0f >", in: "count: 4 others:< weight: 17.0f >",
out: &MyMessage{ out: &MyMessage{
Count: Int32(4), Count: Int32(4),
Others: []*OtherMessage{ Others: []*OtherMessage{
{ {
Weight: Float32(17), Weight: Float32(17),
@@ -197,69 +197,69 @@ var unMarshalTextTests = []UnmarshalTextTest{
// Floating point positive infinity // Floating point positive infinity
{ {
in: "count: 4 bigfloat: inf", in: "count: 4 bigfloat: inf",
out: &MyMessage{ out: &MyMessage{
Count: Int32(4), Count: Int32(4),
Bigfloat: Float64(math.Inf(1)), Bigfloat: Float64(math.Inf(1)),
}, },
}, },
// Floating point negative infinity // Floating point negative infinity
{ {
in: "count: 4 bigfloat: -inf", in: "count: 4 bigfloat: -inf",
out: &MyMessage{ out: &MyMessage{
Count: Int32(4), Count: Int32(4),
Bigfloat: Float64(math.Inf(-1)), Bigfloat: Float64(math.Inf(-1)),
}, },
}, },
// Number too large for float32 // Number too large for float32
{ {
in: "others:< weight: 12345678901234567890123456789012345678901234567890 >", in: "others:< weight: 12345678901234567890123456789012345678901234567890 >",
err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890", err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890",
}, },
// Number posing as a quoted string // Number posing as a quoted string
{ {
in: `inner: < host: 12 >` + "\n", in: `inner: < host: 12 >` + "\n",
err: `line 1.15: invalid string: 12`, err: `line 1.15: invalid string: 12`,
}, },
// Quoted string posing as int32 // Quoted string posing as int32
{ {
in: `count: "12"`, in: `count: "12"`,
err: `line 1.7: invalid int32: "12"`, err: `line 1.7: invalid int32: "12"`,
}, },
// Quoted string posing a float32 // Quoted string posing a float32
{ {
in: `others:< weight: "17.4" >`, in: `others:< weight: "17.4" >`,
err: `line 1.17: invalid float32: "17.4"`, err: `line 1.17: invalid float32: "17.4"`,
}, },
// Enum // Enum
{ {
in: `count:42 bikeshed: BLUE`, in: `count:42 bikeshed: BLUE`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Bikeshed: MyMessage_BLUE.Enum(), Bikeshed: MyMessage_BLUE.Enum(),
}, },
}, },
// Repeated field // Repeated field
{ {
in: `count:42 pet: "horsey" pet:"bunny"`, in: `count:42 pet: "horsey" pet:"bunny"`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Pet: []string{"horsey", "bunny"}, Pet: []string{"horsey", "bunny"},
}, },
}, },
// Repeated message with/without colon and <>/{} // Repeated message with/without colon and <>/{}
{ {
in: `count:42 others:{} others{} others:<> others:{}`, in: `count:42 others:{} others{} others:<> others:{}`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Others: []*OtherMessage{ Others: []*OtherMessage{
{}, {},
{}, {},
@@ -271,9 +271,9 @@ var unMarshalTextTests = []UnmarshalTextTest{
// Missing colon for inner message // Missing colon for inner message
{ {
in: `count:42 inner < host: "cauchy.syd" >`, in: `count:42 inner < host: "cauchy.syd" >`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("cauchy.syd"), Host: String("cauchy.syd"),
}, },
@@ -282,33 +282,33 @@ var unMarshalTextTests = []UnmarshalTextTest{
// Missing colon for string field // Missing colon for string field
{ {
in: `name "Dave"`, in: `name "Dave"`,
err: `line 1.5: expected ':', found "\"Dave\""`, err: `line 1.5: expected ':', found "\"Dave\""`,
}, },
// Missing colon for int32 field // Missing colon for int32 field
{ {
in: `count 42`, in: `count 42`,
err: `line 1.6: expected ':', found "42"`, err: `line 1.6: expected ':', found "42"`,
}, },
// Missing required field // Missing required field
{ {
in: ``, in: ``,
err: `line 1.0: message testdata.MyMessage missing required field "count"`, err: `line 1.0: message testdata.MyMessage missing required field "count"`,
}, },
// Repeated non-repeated field // Repeated non-repeated field
{ {
in: `name: "Rob" name: "Russ"`, in: `name: "Rob" name: "Russ"`,
err: `line 1.12: non-repeated field "name" was repeated`, err: `line 1.12: non-repeated field "name" was repeated`,
}, },
// Group // Group
{ {
in: `count: 17 SomeGroup { group_field: 12 }`, in: `count: 17 SomeGroup { group_field: 12 }`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(17), Count: Int32(17),
Somegroup: &MyMessage_SomeGroup{ Somegroup: &MyMessage_SomeGroup{
GroupField: Int32(12), GroupField: Int32(12),
}, },
@@ -317,18 +317,18 @@ var unMarshalTextTests = []UnmarshalTextTest{
// Semicolon between fields // Semicolon between fields
{ {
in: `count:3;name:"Calvin"`, in: `count:3;name:"Calvin"`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(3), Count: Int32(3),
Name: String("Calvin"), Name: String("Calvin"),
}, },
}, },
// Comma between fields // Comma between fields
{ {
in: `count:4,name:"Ezekiel"`, in: `count:4,name:"Ezekiel"`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(4), Count: Int32(4),
Name: String("Ezekiel"), Name: String("Ezekiel"),
}, },
}, },
@@ -363,25 +363,25 @@ var unMarshalTextTests = []UnmarshalTextTest{
` >` + ` >` +
`>`, `>`,
out: &MyMessage{ out: &MyMessage{
Count: Int32(42), Count: Int32(42),
Name: String("Dave"), Name: String("Dave"),
Quote: String(`"I didn't want to go."`), Quote: String(`"I didn't want to go."`),
Pet: []string{"bunny", "kitty", "horsey"}, Pet: []string{"bunny", "kitty", "horsey"},
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("footrest.syd"), Host: String("footrest.syd"),
Port: Int32(7001), Port: Int32(7001),
Connected: Bool(true), Connected: Bool(true),
}, },
Others: []*OtherMessage{ Others: []*OtherMessage{
{ {
Key: Int64(3735928559), Key: Int64(3735928559),
Value: []byte{0x1, 'A', '\a', '\f'}, Value: []byte{0x1, 'A', '\a', '\f'},
}, },
{ {
Weight: Float32(58.9), Weight: Float32(58.9),
Inner: &InnerMessage{ Inner: &InnerMessage{
Host: String("lesha.mtv"), Host: String("lesha.mtv"),
Port: Int32(8002), Port: Int32(8002),
}, },
}, },
}, },

View File

@@ -39,42 +39,42 @@ import (
"strings" "strings"
"testing" "testing"
"code.google.com/p/goprotobuf/proto" "github.com/coreos/etcd/third_party/code.google.com/p/goprotobuf/proto"
pb "./testdata" pb "./testdata"
) )
func newTestMessage() *pb.MyMessage { func newTestMessage() *pb.MyMessage {
msg := &pb.MyMessage{ msg := &pb.MyMessage{
Count: proto.Int32(42), Count: proto.Int32(42),
Name: proto.String("Dave"), Name: proto.String("Dave"),
Quote: proto.String(`"I didn't want to go."`), Quote: proto.String(`"I didn't want to go."`),
Pet: []string{"bunny", "kitty", "horsey"}, Pet: []string{"bunny", "kitty", "horsey"},
Inner: &pb.InnerMessage{ Inner: &pb.InnerMessage{
Host: proto.String("footrest.syd"), Host: proto.String("footrest.syd"),
Port: proto.Int32(7001), Port: proto.Int32(7001),
Connected: proto.Bool(true), Connected: proto.Bool(true),
}, },
Others: []*pb.OtherMessage{ Others: []*pb.OtherMessage{
{ {
Key: proto.Int64(0xdeadbeef), Key: proto.Int64(0xdeadbeef),
Value: []byte{1, 65, 7, 12}, Value: []byte{1, 65, 7, 12},
}, },
{ {
Weight: proto.Float32(6.022), Weight: proto.Float32(6.022),
Inner: &pb.InnerMessage{ Inner: &pb.InnerMessage{
Host: proto.String("lesha.mtv"), Host: proto.String("lesha.mtv"),
Port: proto.Int32(8002), Port: proto.Int32(8002),
}, },
}, },
}, },
Bikeshed: pb.MyMessage_BLUE.Enum(), Bikeshed: pb.MyMessage_BLUE.Enum(),
Somegroup: &pb.MyMessage_SomeGroup{ Somegroup: &pb.MyMessage_SomeGroup{
GroupField: proto.Int32(8), GroupField: proto.Int32(8),
}, },
// One normally wouldn't do this. // One normally wouldn't do this.
// This is an undeclared tag 13, as a varint (wire type 0) with value 4. // This is an undeclared tag 13, as a varint (wire type 0) with value 4.
XXX_unrecognized: []byte{13<<3 | 0, 4}, XXX_unrecognized: []byte{13<<3 | 0, 4},
} }
ext := &pb.Ext{ ext := &pb.Ext{
Data: proto.String("Big gobs for big rats"), Data: proto.String("Big gobs for big rats"),
@@ -250,8 +250,8 @@ func TestCompactText(t *testing.T) {
func TestStringEscaping(t *testing.T) { func TestStringEscaping(t *testing.T) {
testCases := []struct { testCases := []struct {
in *pb.Strings in *pb.Strings
out string out string
}{ }{
{ {
// Test data from C++ test (TextFormatTest.StringEscape). // Test data from C++ test (TextFormatTest.StringEscape).
@@ -299,8 +299,8 @@ func TestStringEscaping(t *testing.T) {
// This is a proxy for something like a nearly-full or imminently-failing disk, // This is a proxy for something like a nearly-full or imminently-failing disk,
// or a network connection that is about to die. // or a network connection that is about to die.
type limitedWriter struct { type limitedWriter struct {
b bytes.Buffer b bytes.Buffer
limit int limit int
} }
var outOfSpace = errors.New("proto: insufficient space") var outOfSpace = errors.New("proto: insufficient space")
@@ -337,8 +337,8 @@ func TestMarshalTextFailing(t *testing.T) {
func TestFloats(t *testing.T) { func TestFloats(t *testing.T) {
tests := []struct { tests := []struct {
f float64 f float64
want string want string
}{ }{
{0, "0"}, {0, "0"},
{4.7, "4.7"}, {4.7, "4.7"},

View File

@@ -4,39 +4,39 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/BurntSushi/toml" "github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
) )
type tomlConfig struct { type tomlConfig struct {
Title string Title string
Owner ownerInfo Owner ownerInfo
DB database `toml:"database"` DB database `toml:"database"`
Servers map[string]server Servers map[string]server
Clients clients Clients clients
} }
type ownerInfo struct { type ownerInfo struct {
Name string Name string
Org string `toml:"organization"` Org string `toml:"organization"`
Bio string Bio string
DOB time.Time DOB time.Time
} }
type database struct { type database struct {
Server string Server string
Ports []int Ports []int
ConnMax int `toml:"connection_max"` ConnMax int `toml:"connection_max"`
Enabled bool Enabled bool
} }
type server struct { type server struct {
IP string IP string
DC string DC string
} }
type clients struct { type clients struct {
Data [][]interface{} Data [][]interface{}
Hosts []string Hosts []string
} }
func main() { func main() {

Some files were not shown because too many files have changed in this diff Show More