1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00
go-micro/registry/encoding_test.go

66 lines
1.2 KiB
Go
Raw Normal View History

2016-03-16 23:23:41 +02:00
package registry
import (
"testing"
)
2019-01-15 18:50:37 +02:00
func TestEncoding(t *testing.T) {
testData := []*mdnsTxt{
{
2019-01-15 18:50:37 +02:00
Version: "1.0.0",
2016-03-29 19:16:55 +02:00
Metadata: map[string]string{
2019-01-15 18:50:37 +02:00
"foo": "bar",
2016-03-29 19:16:55 +02:00
},
2019-01-15 18:50:37 +02:00
Endpoints: []*Endpoint{
{
2019-01-15 18:50:37 +02:00
Name: "endpoint1",
Request: &Value{
Name: "request",
Type: "request",
},
Response: &Value{
Name: "response",
Type: "response",
},
Metadata: map[string]string{
"foo1": "bar1",
},
},
2016-03-16 23:23:41 +02:00
},
},
}
2019-01-15 18:50:37 +02:00
for _, d := range testData {
encoded, err := encode(d)
if err != nil {
t.Fatal(err)
2016-03-16 23:23:41 +02:00
}
2019-01-15 18:50:37 +02:00
for _, txt := range encoded {
if len(txt) > 255 {
t.Fatalf("One of parts for txt is %d characters", len(txt))
2016-03-16 23:23:41 +02:00
}
}
2016-03-29 19:16:55 +02:00
2019-01-15 18:50:37 +02:00
decoded, err := decode(encoded)
2016-03-29 19:16:55 +02:00
if err != nil {
t.Fatal(err)
}
2019-01-15 18:50:37 +02:00
if decoded.Version != d.Version {
t.Fatalf("Expected version %s got %s", d.Version, decoded.Version)
2016-03-16 23:23:41 +02:00
}
2019-01-15 18:50:37 +02:00
if len(decoded.Endpoints) != len(d.Endpoints) {
t.Fatalf("Expected %d endpoints, got %d", len(d.Endpoints), len(decoded.Endpoints))
2016-03-16 23:23:41 +02:00
}
2019-01-15 18:50:37 +02:00
for k, v := range d.Metadata {
if val := decoded.Metadata[k]; val != v {
t.Fatalf("Expected %s=%s got %s=%s", k, v, k, val)
}
2016-03-16 23:23:41 +02:00
}
}
2019-01-15 18:50:37 +02:00
2016-03-16 23:23:41 +02:00
}