Skip to content

Commit cbaebfa

Browse files
committed
write protobuf in tests
1 parent b2369bd commit cbaebfa

8 files changed

Lines changed: 29 additions & 19 deletions

pkg/roles/dns/api_records_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAPIRecordsGet(t *testing.T) {
2424
types.KeyZones,
2525
zone,
2626
).String(),
27-
tests.MustJSON(dns.ZoneContext{}),
27+
tests.MustPB(&types.Zone{}),
2828
)
2929
inst.KV().Put(
3030
ctx,
@@ -35,7 +35,7 @@ func TestAPIRecordsGet(t *testing.T) {
3535
"test",
3636
"A",
3737
).String(),
38-
tests.MustJSON(types.Record{
38+
tests.MustPB(&types.Record{
3939
Data: "192.0.2.1",
4040
}),
4141
)
@@ -61,7 +61,7 @@ func TestAPIRecordsPut(t *testing.T) {
6161
types.KeyZones,
6262
name,
6363
).String(),
64-
tests.MustJSON(dns.ZoneContext{}),
64+
tests.MustPB(&types.Zone{}),
6565
)
6666
assert.NoError(t, role.APIRecordsPut().Interact(ctx, dns.APIRecordsPutInput{
6767
Zone: name,
@@ -100,7 +100,7 @@ func TestAPIRecordsDelete(t *testing.T) {
100100
types.KeyZones,
101101
zone,
102102
).String(),
103-
tests.MustJSON(dns.ZoneContext{}),
103+
tests.MustPB(&types.Zone{}),
104104
)
105105
inst.KV().Put(
106106
ctx,
@@ -111,7 +111,7 @@ func TestAPIRecordsDelete(t *testing.T) {
111111
"test",
112112
"A",
113113
).String(),
114-
tests.MustJSON(types.Record{
114+
tests.MustPB(&types.Record{
115115
Data: "192.0.2.1",
116116
}),
117117
)

pkg/roles/dns/api_zones_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestAPIZonesGet(t *testing.T) {
2525
types.KeyZones,
2626
"test.",
2727
).String(),
28-
tests.MustJSON(dns.ZoneContext{}),
28+
tests.MustPB(&types.Zone{}),
2929
)
3030

3131
var output dns.APIZonesGetOutput
@@ -86,7 +86,7 @@ func TestAPIZonesDelete(t *testing.T) {
8686
types.KeyZones,
8787
name,
8888
).String(),
89-
tests.MustJSON(dns.ZoneContext{}),
89+
tests.MustPB(&types.Zone{}),
9090
)
9191

9292
assert.NoError(t, role.APIZonesDelete().Interact(ctx, dns.APIZonesDeleteInput{

pkg/roles/dns/handler_coredns_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestRoleDNSHandlerCoreDNS(t *testing.T) {
3030
types.KeyZones,
3131
".",
3232
).String(),
33-
tests.MustJSON(types.Zone{
33+
tests.MustPB(&types.Zone{
3434
HandlerConfigs: []*structpb.Struct{
3535
{
3636
Fields: map[string]*structpb.Value{

pkg/roles/dns/handler_etcd_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestRoleDNS_Etcd(t *testing.T) {
2424
types.KeyZones,
2525
".",
2626
).String(),
27-
tests.MustJSON(types.Zone{
27+
tests.MustPB(&types.Zone{
2828
HandlerConfigs: []*structpb.Struct{
2929
{
3030
Fields: map[string]*structpb.Value{
@@ -44,7 +44,7 @@ func TestRoleDNS_Etcd(t *testing.T) {
4444
types.DNSRecordTypeA,
4545
"0",
4646
).String(),
47-
tests.MustJSON(types.Record{
47+
tests.MustPB(&types.Record{
4848
Data: "10.1.2.3",
4949
}),
5050
)
@@ -70,7 +70,7 @@ func TestRoleDNS_Etcd_Wildcard(t *testing.T) {
7070
types.KeyZones,
7171
".",
7272
).String(),
73-
tests.MustJSON(types.Zone{
73+
tests.MustPB(&types.Zone{
7474
HandlerConfigs: []*structpb.Struct{
7575
{
7676
Fields: map[string]*structpb.Value{
@@ -90,7 +90,7 @@ func TestRoleDNS_Etcd_Wildcard(t *testing.T) {
9090
types.DNSRecordTypeA,
9191
"0",
9292
).String(),
93-
tests.MustJSON(types.Record{
93+
tests.MustPB(&types.Record{
9494
Data: "10.1.2.3",
9595
}),
9696
)
@@ -116,7 +116,7 @@ func TestRoleDNS_Etcd_WildcardNested(t *testing.T) {
116116
types.KeyZones,
117117
".",
118118
).String(),
119-
tests.MustJSON(types.Zone{
119+
tests.MustPB(&types.Zone{
120120
HandlerConfigs: []*structpb.Struct{
121121
{
122122
Fields: map[string]*structpb.Value{
@@ -136,7 +136,7 @@ func TestRoleDNS_Etcd_WildcardNested(t *testing.T) {
136136
types.DNSRecordTypeA,
137137
"0",
138138
).String(),
139-
tests.MustJSON(types.Record{
139+
tests.MustPB(&types.Record{
140140
Data: "10.1.2.3",
141141
}),
142142
)

pkg/roles/dns/handler_forward_blocky_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestRoleDNS_BlockyForwarder(t *testing.T) {
3232
types.KeyZones,
3333
".",
3434
).String(),
35-
tests.MustJSON(types.Zone{
35+
tests.MustPB(&types.Zone{
3636
HandlerConfigs: []*structpb.Struct{
3737
{
3838
Fields: map[string]*structpb.Value{

pkg/roles/dns/handler_forward_ip_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestRoleDNS_IPForwarder_v4(t *testing.T) {
2525
types.KeyZones,
2626
".",
2727
).String(),
28-
tests.MustJSON(types.Zone{
28+
tests.MustPB(&types.Zone{
2929
HandlerConfigs: []*structpb.Struct{
3030
{
3131
Fields: map[string]*structpb.Value{
@@ -65,7 +65,7 @@ func TestRoleDNS_IPForwarder_v4_Cache(t *testing.T) {
6565
types.KeyZones,
6666
".",
6767
).String(),
68-
tests.MustJSON(types.Zone{
68+
tests.MustPB(&types.Zone{
6969
HandlerConfigs: []*structpb.Struct{
7070
{
7171
Fields: map[string]*structpb.Value{
@@ -112,7 +112,7 @@ func TestRoleDNS_IPForwarder_v6(t *testing.T) {
112112
types.KeyZones,
113113
".",
114114
).String(),
115-
tests.MustJSON(types.Zone{
115+
tests.MustPB(&types.Zone{
116116
HandlerConfigs: []*structpb.Struct{
117117
{
118118
Fields: map[string]*structpb.Value{

pkg/roles/dns/zone_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestRoleDNSZoneFind(t *testing.T) {
2222
types.KeyZones,
2323
".",
2424
).String(),
25-
tests.MustJSON(types.Zone{
25+
tests.MustPB(&types.Zone{
2626
HandlerConfigs: []*structpb.Struct{
2727
{
2828
Fields: map[string]*structpb.Value{

pkg/tests/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/google/uuid"
1717
"github.com/stretchr/testify/assert"
1818
clientv3 "go.etcd.io/etcd/client/v3"
19+
"google.golang.org/protobuf/proto"
20+
"google.golang.org/protobuf/reflect/protoreflect"
1921
)
2022

2123
func MustJSON(in interface{}) string {
@@ -26,6 +28,14 @@ func MustJSON(in interface{}) string {
2628
return string(j)
2729
}
2830

31+
func MustPB(m protoreflect.ProtoMessage) string {
32+
raw, err := proto.Marshal(m)
33+
if err != nil {
34+
panic(err)
35+
}
36+
return string(raw)
37+
}
38+
2939
func Context() context.Context {
3040
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) //nolint
3141
return sentry.StartTransaction(ctx, "test").Context()

0 commit comments

Comments
 (0)