diff --git a/pkg/roles/dns/api_records_test.go b/pkg/roles/dns/api_records_test.go index 4448b4127..93691989e 100644 --- a/pkg/roles/dns/api_records_test.go +++ b/pkg/roles/dns/api_records_test.go @@ -24,7 +24,7 @@ func TestAPIRecordsGet(t *testing.T) { types.KeyZones, zone, ).String(), - tests.MustJSON(dns.ZoneContext{}), + tests.MustPB(&types.Zone{}), ) inst.KV().Put( ctx, @@ -35,7 +35,7 @@ func TestAPIRecordsGet(t *testing.T) { "test", "A", ).String(), - tests.MustJSON(types.Record{ + tests.MustPB(&types.Record{ Data: "192.0.2.1", }), ) @@ -61,7 +61,7 @@ func TestAPIRecordsPut(t *testing.T) { types.KeyZones, name, ).String(), - tests.MustJSON(dns.ZoneContext{}), + tests.MustPB(&types.Zone{}), ) assert.NoError(t, role.APIRecordsPut().Interact(ctx, dns.APIRecordsPutInput{ Zone: name, @@ -100,7 +100,7 @@ func TestAPIRecordsDelete(t *testing.T) { types.KeyZones, zone, ).String(), - tests.MustJSON(dns.ZoneContext{}), + tests.MustPB(&types.Zone{}), ) inst.KV().Put( ctx, @@ -111,7 +111,7 @@ func TestAPIRecordsDelete(t *testing.T) { "test", "A", ).String(), - tests.MustJSON(types.Record{ + tests.MustPB(&types.Record{ Data: "192.0.2.1", }), ) diff --git a/pkg/roles/dns/api_zones_test.go b/pkg/roles/dns/api_zones_test.go index 3415aef03..2a4e8e71f 100644 --- a/pkg/roles/dns/api_zones_test.go +++ b/pkg/roles/dns/api_zones_test.go @@ -25,7 +25,7 @@ func TestAPIZonesGet(t *testing.T) { types.KeyZones, "test.", ).String(), - tests.MustJSON(dns.ZoneContext{}), + tests.MustPB(&types.Zone{}), ) var output dns.APIZonesGetOutput @@ -86,7 +86,7 @@ func TestAPIZonesDelete(t *testing.T) { types.KeyZones, name, ).String(), - tests.MustJSON(dns.ZoneContext{}), + tests.MustPB(&types.Zone{}), ) assert.NoError(t, role.APIZonesDelete().Interact(ctx, dns.APIZonesDeleteInput{ diff --git a/pkg/roles/dns/handler_coredns_test.go b/pkg/roles/dns/handler_coredns_test.go index 90e7a28b4..acea8b83e 100644 --- a/pkg/roles/dns/handler_coredns_test.go +++ b/pkg/roles/dns/handler_coredns_test.go @@ -30,7 +30,7 @@ func TestRoleDNSHandlerCoreDNS(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ diff --git a/pkg/roles/dns/handler_etcd_test.go b/pkg/roles/dns/handler_etcd_test.go index 9f7ea225d..b5a204d93 100644 --- a/pkg/roles/dns/handler_etcd_test.go +++ b/pkg/roles/dns/handler_etcd_test.go @@ -24,7 +24,7 @@ func TestRoleDNS_Etcd(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ @@ -44,7 +44,7 @@ func TestRoleDNS_Etcd(t *testing.T) { types.DNSRecordTypeA, "0", ).String(), - tests.MustJSON(types.Record{ + tests.MustPB(&types.Record{ Data: "10.1.2.3", }), ) @@ -70,7 +70,7 @@ func TestRoleDNS_Etcd_Wildcard(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ @@ -90,7 +90,7 @@ func TestRoleDNS_Etcd_Wildcard(t *testing.T) { types.DNSRecordTypeA, "0", ).String(), - tests.MustJSON(types.Record{ + tests.MustPB(&types.Record{ Data: "10.1.2.3", }), ) @@ -116,7 +116,7 @@ func TestRoleDNS_Etcd_WildcardNested(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ @@ -136,7 +136,7 @@ func TestRoleDNS_Etcd_WildcardNested(t *testing.T) { types.DNSRecordTypeA, "0", ).String(), - tests.MustJSON(types.Record{ + tests.MustPB(&types.Record{ Data: "10.1.2.3", }), ) diff --git a/pkg/roles/dns/handler_forward_blocky_test.go b/pkg/roles/dns/handler_forward_blocky_test.go index d5069b6ec..65e5b4838 100644 --- a/pkg/roles/dns/handler_forward_blocky_test.go +++ b/pkg/roles/dns/handler_forward_blocky_test.go @@ -32,7 +32,7 @@ func TestRoleDNS_BlockyForwarder(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ diff --git a/pkg/roles/dns/handler_forward_ip_test.go b/pkg/roles/dns/handler_forward_ip_test.go index 8647ab5fb..9a4ada4b0 100644 --- a/pkg/roles/dns/handler_forward_ip_test.go +++ b/pkg/roles/dns/handler_forward_ip_test.go @@ -25,7 +25,7 @@ func TestRoleDNS_IPForwarder_v4(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ @@ -65,7 +65,7 @@ func TestRoleDNS_IPForwarder_v4_Cache(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ @@ -112,7 +112,7 @@ func TestRoleDNS_IPForwarder_v6(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ diff --git a/pkg/roles/dns/zone_test.go b/pkg/roles/dns/zone_test.go index b38b7874c..7332bf1f0 100644 --- a/pkg/roles/dns/zone_test.go +++ b/pkg/roles/dns/zone_test.go @@ -22,7 +22,7 @@ func TestRoleDNSZoneFind(t *testing.T) { types.KeyZones, ".", ).String(), - tests.MustJSON(types.Zone{ + tests.MustPB(&types.Zone{ HandlerConfigs: []*structpb.Struct{ { Fields: map[string]*structpb.Value{ diff --git a/pkg/tests/utils.go b/pkg/tests/utils.go index 7de529cdb..45f423b2c 100644 --- a/pkg/tests/utils.go +++ b/pkg/tests/utils.go @@ -16,6 +16,8 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/assert" clientv3 "go.etcd.io/etcd/client/v3" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" ) func MustJSON(in interface{}) string { @@ -26,6 +28,14 @@ func MustJSON(in interface{}) string { return string(j) } +func MustPB(m protoreflect.ProtoMessage) string { + raw, err := proto.Marshal(m) + if err != nil { + panic(err) + } + return string(raw) +} + func Context() context.Context { ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) //nolint return sentry.StartTransaction(ctx, "test").Context()