Fix owner and owner mapping

pull/10616/head
Leonardo Di Donato 2018-07-30 17:11:29 +02:00 committed by Leonardo Di Donato
parent d3c18e58ae
commit 02e4659d42
2 changed files with 26 additions and 26 deletions

View File

@ -1,7 +1,5 @@
package platform package platform
import "encoding/hex"
// Owner represents a resource owner // Owner represents a resource owner
type Owner struct { type Owner struct {
ID ID ID ID
@ -9,11 +7,10 @@ type Owner struct {
// Decode parses b as a hex-encoded byte-slice-string. // Decode parses b as a hex-encoded byte-slice-string.
func (o *Owner) Decode(b []byte) error { func (o *Owner) Decode(b []byte) error {
dst := make([]byte, hex.DecodedLen(len(b))) var id ID
_, err := hex.Decode(dst, b) if err := id.Decode(b); err != nil {
if err != nil {
return err return err
} }
o.ID = dst o.ID = id
return nil return nil
} }

View File

@ -1,39 +1,42 @@
package platform package platform_test
import ( import (
"testing" "testing"
"github.com/influxdata/platform"
platformtesting "github.com/influxdata/platform/testing"
) )
func TestOwnerMappingValidate(t *testing.T) { func TestOwnerMappingValidate(t *testing.T) {
type fields struct { type fields struct {
ResourceID ID ResourceID platform.ID
Owner Owner Owner platform.Owner
} }
tests := []struct { tests := []struct {
name string name string
fields fields fields fields
wantErr bool wantErr bool
}{ }{
{ {
name: "mapping requires a resourceid", name: "mapping requires a resourceid",
fields: fields{ fields: fields{
Owner: Owner{ Owner: platform.Owner{
ID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef}, ID: platformtesting.MustIDFromString(t, "debac1e0deadbeef"),
}, },
}, },
wantErr: true, wantErr: true,
},
{
name: "mapping requires an Owner",
fields: fields{
ResourceID: platformtesting.MustIDFromString(t, "debac1e0deadbeef"),
},
wantErr: true,
}, },
{
name: "mapping requires an Owner",
fields: fields{
ResourceID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
},
wantErr: true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
m := OwnerMapping{ m := platform.OwnerMapping{
ResourceID: tt.fields.ResourceID, ResourceID: tt.fields.ResourceID,
Owner: tt.fields.Owner, Owner: tt.fields.Owner,
} }