-
Notifications
You must be signed in to change notification settings - Fork 1
/
proto_test.go
167 lines (140 loc) · 3.75 KB
/
proto_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package mesos
import (
"testing"
"github.com/golang/protobuf/proto"
"github.com/mesos/go-proto/mesos/v1"
"github.com/mesos/go-proto/mesos/v1/agent"
"github.com/mesos/go-proto/mesos/v1/allocator"
"github.com/mesos/go-proto/mesos/v1/executor"
"github.com/mesos/go-proto/mesos/v1/maintenance"
"github.com/mesos/go-proto/mesos/v1/master"
"github.com/mesos/go-proto/mesos/v1/scheduler"
)
func newAgentID(id string) *mesos_v1.AgentID {
return &mesos_v1.AgentID{
Value: proto.String(id),
}
}
func newFrameworkID(id string) *mesos_v1.FrameworkID {
return &mesos_v1.FrameworkID{
Value: proto.String(id),
}
}
func newTaskID(id string) *mesos_v1.TaskID {
return &mesos_v1.TaskID{
Value: proto.String(id),
}
}
// Test that we can import the mesos_v1 package.
func TestMesosProto(t *testing.T) {
task := mesos_v1.TaskInfo{
Name: proto.String("check"),
TaskId: newTaskID("task-id-1"),
AgentId: newAgentID("agent-id-1"),
}
data, err := proto.Marshal(&task)
if err != nil {
t.Errorf("marshalling TaskInfo: %s", err)
}
err = proto.Unmarshal(data, &task)
if err != nil {
t.Errorf("unmarshalling TaskInfo: %s", err)
}
}
// Test that we can import the mesos_v1_executor package.
func TestExecutorProto(t *testing.T) {
event := mesos_v1_executor.Event{
Type: mesos_v1_executor.Event_UNKNOWN.Enum(),
}
data, err := proto.Marshal(&event)
if err != nil {
t.Errorf("marshalling Event: %s", err)
}
err = proto.Unmarshal(data, &event)
if err != nil {
t.Errorf("unmarshalling Event: %s", err)
}
}
// Test that we can import the mesos_v1_agent package.
func TestAgentProto(t *testing.T) {
call := mesos_v1_agent.Call{
Type: mesos_v1_agent.Call_GET_HEALTH.Enum(),
}
data, err := proto.Marshal(&call)
if err != nil {
t.Errorf("marshalling Call: %s", err)
}
err = proto.Unmarshal(data, &call)
if err != nil {
t.Errorf("unmarshalling Call: %s", err)
}
}
// Test that we can import the mesos_v1_allocator package.
func TestAllocatorProto(t *testing.T) {
status := mesos_v1_allocator.InverseOfferStatus{
Status: mesos_v1_allocator.InverseOfferStatus_ACCEPT.Enum(),
Timestamp: &mesos_v1.TimeInfo{
Nanoseconds: proto.Int64(0),
},
FrameworkId: newFrameworkID("framework-1"),
}
data, err := proto.Marshal(&status)
if err != nil {
t.Errorf("marshalling InverseOfferStatus: %s", err)
}
err = proto.Unmarshal(data, &status)
if err != nil {
t.Errorf("unmarshalling InverseOfferStatus: %s", err)
}
}
// Test that we can import the mesos_v1_maintenance package.
func TestMaintenanceProto(t *testing.T) {
window := mesos_v1_maintenance.Window{
MachineIds: nil,
Unavailability: &mesos_v1.Unavailability{
Start: &mesos_v1.TimeInfo{
Nanoseconds: proto.Int64(0),
},
Duration: &mesos_v1.DurationInfo{
Nanoseconds: proto.Int64(0),
},
},
}
data, err := proto.Marshal(&window)
if err != nil {
t.Errorf("marshalling Window: %s", err)
}
err = proto.Unmarshal(data, &window)
if err != nil {
t.Errorf("unmarshalling Window: %s", err)
}
}
// Test that we can import the mesos_v1_master package.
func TestMasterProto(t *testing.T) {
call := mesos_v1_master.Call{
Type: mesos_v1_master.Call_GET_HEALTH.Enum(),
}
data, err := proto.Marshal(&call)
if err != nil {
t.Errorf("marshalling Call: %s", err)
}
err = proto.Unmarshal(data, &call)
if err != nil {
t.Errorf("unmarshalling Call: %s", err)
}
}
// Test that we can import the mesos_v1_scheduler package.
func TestSchedulerProto(t *testing.T) {
call := mesos_v1_scheduler.Call{
FrameworkId: newFrameworkID("framework-1"),
Type: mesos_v1_scheduler.Call_SUBSCRIBE.Enum(),
}
data, err := proto.Marshal(&call)
if err != nil {
t.Errorf("marshalling Call: %s", err)
}
err = proto.Unmarshal(data, &call)
if err != nil {
t.Errorf("unmarshalling Call: %s", err)
}
}