influxdb/user_resource_mapping_test.go

89 lines
2.2 KiB
Go
Raw Normal View History

2018-07-30 21:46:30 +00:00
package platform
import (
"testing"
)
func TestOwnerMappingValidate(t *testing.T) {
type fields struct {
2018-10-04 21:08:31 +00:00
ResourceID ID
ResourceType ResourceType
UserID ID
UserType UserType
2018-07-30 21:46:30 +00:00
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "mapping requires a resourceid",
fields: fields{
2018-10-04 21:08:31 +00:00
UserID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserType: Owner,
ResourceType: DashboardResourceType,
2018-07-30 21:46:30 +00:00
},
wantErr: true,
},
{
2018-10-04 21:08:31 +00:00
name: "mapping requires a userid",
2018-07-30 21:46:30 +00:00
fields: fields{
2018-10-04 21:08:31 +00:00
ResourceID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserType: Owner,
ResourceType: DashboardResourceType,
2018-07-30 21:46:30 +00:00
},
wantErr: true,
},
{
name: "mapping requires a usertype",
2018-10-04 21:08:31 +00:00
fields: fields{
ResourceID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
ResourceType: DashboardResourceType,
},
wantErr: true,
},
{
name: "mapping requires a resourcetype",
2018-07-30 21:46:30 +00:00
fields: fields{
ResourceID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
2018-10-04 21:08:31 +00:00
UserType: Owner,
2018-07-30 21:46:30 +00:00
},
wantErr: true,
},
{
name: "the usertype provided must be valid",
fields: fields{
2018-10-04 21:08:31 +00:00
ResourceID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserType: "foo",
ResourceType: DashboardResourceType,
},
wantErr: true,
},
{
name: "the resourcetype provided must be valid",
fields: fields{
ResourceID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserID: []byte{0xde, 0xba, 0xc1, 0xe0, 0xde, 0xad, 0xbe, 0xef},
UserType: Owner,
ResourceType: "foo",
2018-07-30 21:46:30 +00:00
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := UserResourceMapping{
ResourceID: tt.fields.ResourceID,
UserID: tt.fields.UserID,
UserType: tt.fields.UserType,
}
if err := m.Validate(); (err != nil) != tt.wantErr {
t.Errorf("OwnerMapping.Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}