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

View File

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