feat(testing): revisit telegraf config tests for filtering/restricting by org

pull/10616/head
Leonardo Di Donato 2019-01-09 20:13:06 +01:00 committed by Leonardo Di Donato
parent ff820d5a3d
commit c720393c45
3 changed files with 296 additions and 128 deletions

View File

@ -18,10 +18,6 @@ const (
dashThreeID = "020f755c3c082002" dashThreeID = "020f755c3c082002"
) )
func idPtr(id platform.ID) *platform.ID {
return &id
}
func int32Ptr(i int32) *int32 { func int32Ptr(i int32) *int32 {
return &i return &i
} }

View File

@ -115,16 +115,34 @@ func CreateTelegrafConfig(
args args args args
wants wants wants wants
}{ }{
{
name: "create telegraf config without organization ID should error",
fields: TelegrafConfigFields{
IDGenerator: mock.NewIDGenerator(oneID, t),
TelegrafConfigs: []*platform.TelegrafConfig{},
UserResourceMappings: []*platform.UserResourceMapping{},
},
args: args{
telegrafConfig: &platform.TelegrafConfig{},
},
wants: wants{
err: &platform.Error{
Code: platform.EEmptyValue,
Msg: platform.ErrTelegrafConfigInvalidOrganizationID,
},
},
},
{ {
name: "create telegraf config with empty set", name: "create telegraf config with empty set",
fields: TelegrafConfigFields{ fields: TelegrafConfigFields{
IDGenerator: &loopIDGenerator{s: []string{oneID, twoID}}, IDGenerator: mock.NewIDGenerator(oneID, t),
TelegrafConfigs: []*platform.TelegrafConfig{}, TelegrafConfigs: []*platform.TelegrafConfig{},
UserResourceMappings: []*platform.UserResourceMapping{}, UserResourceMappings: []*platform.UserResourceMapping{},
}, },
args: args{ args: args{
userID: MustIDBase16(threeID), userID: MustIDBase16(threeID),
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
OrganizationID: MustIDBase16(twoID),
Name: "name1", Name: "name1",
Agent: platform.TelegrafAgentConfig{ Agent: platform.TelegrafAgentConfig{
Interval: 1000, Interval: 1000,
@ -158,6 +176,7 @@ func CreateTelegrafConfig(
telegrafs: []*platform.TelegrafConfig{ telegrafs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "name1", Name: "name1",
Agent: platform.TelegrafAgentConfig{ Agent: platform.TelegrafAgentConfig{
Interval: 1000, Interval: 1000,
@ -188,6 +207,7 @@ func CreateTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "tc1", Name: "tc1",
Agent: platform.TelegrafAgentConfig{ Agent: platform.TelegrafAgentConfig{
Interval: 4000, Interval: 4000,
@ -212,6 +232,7 @@ func CreateTelegrafConfig(
args: args{ args: args{
userID: MustIDBase16(threeID), userID: MustIDBase16(threeID),
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
OrganizationID: MustIDBase16(twoID),
Name: "name2", Name: "name2",
Agent: platform.TelegrafAgentConfig{ Agent: platform.TelegrafAgentConfig{
Interval: 1001, Interval: 1001,
@ -237,6 +258,7 @@ func CreateTelegrafConfig(
telegrafs: []*platform.TelegrafConfig{ telegrafs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "tc1", Name: "tc1",
Agent: platform.TelegrafAgentConfig{ Agent: platform.TelegrafAgentConfig{
Interval: 4000, Interval: 4000,
@ -250,6 +272,7 @@ func CreateTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(twoID),
Name: "name2", Name: "name2",
Agent: platform.TelegrafAgentConfig{ Agent: platform.TelegrafAgentConfig{
Interval: 1001, Interval: 1001,
@ -308,10 +331,13 @@ func CreateTelegrafConfig(
} }
} }
tcs, _, err := s.FindTelegrafConfigs(ctx, platform.UserResourceMappingFilter{ filter := platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(threeID), UserID: MustIDBase16(threeID),
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
}) },
}
tcs, _, err := s.FindTelegrafConfigs(ctx, filter)
if err != nil { if err != nil {
t.Fatalf("failed to retrieve telegraf configs: %v", err) t.Fatalf("failed to retrieve telegraf configs: %v", err)
} }
@ -358,6 +384,7 @@ func FindTelegrafConfigByID(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -367,6 +394,7 @@ func FindTelegrafConfigByID(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(twoID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -399,6 +427,7 @@ func FindTelegrafConfigByID(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -408,6 +437,7 @@ func FindTelegrafConfigByID(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(twoID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -440,6 +470,7 @@ func FindTelegrafConfigByID(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(threeID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -449,6 +480,7 @@ func FindTelegrafConfigByID(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -471,6 +503,7 @@ func FindTelegrafConfigByID(
wants: wants{ wants: wants{
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -517,7 +550,7 @@ func FindTelegrafConfig(
t *testing.T, t *testing.T,
) { ) {
type args struct { type args struct {
filter platform.UserResourceMappingFilter filter platform.TelegrafConfigFilter
} }
type wants struct { type wants struct {
@ -550,6 +583,7 @@ func FindTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -559,6 +593,7 @@ func FindTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -576,16 +611,18 @@ func FindTelegrafConfig(
}, },
}, },
args: args{ args: args{
filter: platform.UserResourceMappingFilter{ filter: platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(threeID), UserID: MustIDBase16(threeID),
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
UserType: platform.Member, UserType: platform.Member,
}, },
}, },
},
wants: wants{ wants: wants{
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -622,6 +659,7 @@ func FindTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -631,6 +669,7 @@ func FindTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -648,11 +687,13 @@ func FindTelegrafConfig(
}, },
}, },
args: args{ args: args{
filter: platform.UserResourceMappingFilter{ filter: platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(fourID), UserID: MustIDBase16(fourID),
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
}, },
}, },
},
wants: wants{ wants: wants{
err: &platform.Error{ err: &platform.Error{
Code: platform.ENotFound, Code: platform.ENotFound,
@ -671,7 +712,6 @@ func FindTelegrafConfig(
if err != nil && tt.wants.err == nil { if err != nil && tt.wants.err == nil {
t.Fatalf("expected errors to be nil got '%v'", err) t.Fatalf("expected errors to be nil got '%v'", err)
} }
if err != nil && tt.wants.err != nil { if err != nil && tt.wants.err != nil {
if platform.ErrorCode(err) != platform.ErrorCode(tt.wants.err) { if platform.ErrorCode(err) != platform.ErrorCode(tt.wants.err) {
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err) t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
@ -690,7 +730,7 @@ func FindTelegrafConfigs(
t *testing.T, t *testing.T,
) { ) {
type args struct { type args struct {
filter platform.UserResourceMappingFilter filter platform.TelegrafConfigFilter
} }
type wants struct { type wants struct {
@ -704,16 +744,18 @@ func FindTelegrafConfigs(
wants wants wants wants
}{ }{
{ {
name: "find nothing", name: "find nothing (empty set)",
fields: TelegrafConfigFields{ fields: TelegrafConfigFields{
UserResourceMappings: []*platform.UserResourceMapping{}, UserResourceMappings: []*platform.UserResourceMapping{},
TelegrafConfigs: []*platform.TelegrafConfig{}, TelegrafConfigs: []*platform.TelegrafConfig{},
}, },
args: args{ args: args{
filter: platform.UserResourceMappingFilter{ filter: platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
}, },
}, },
},
wants: wants{ wants: wants{
telegrafConfigs: []*platform.TelegrafConfig{}, telegrafConfigs: []*platform.TelegrafConfig{},
}, },
@ -738,6 +780,7 @@ func FindTelegrafConfigs(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(threeID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -747,6 +790,7 @@ func FindTelegrafConfigs(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -764,15 +808,18 @@ func FindTelegrafConfigs(
}, },
}, },
args: args{ args: args{
filter: platform.UserResourceMappingFilter{ filter: platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(threeID), UserID: MustIDBase16(threeID),
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
}, },
}, },
},
wants: wants{ wants: wants{
telegrafConfigs: []*platform.TelegrafConfig{ telegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(threeID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -782,6 +829,7 @@ func FindTelegrafConfigs(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -819,6 +867,7 @@ func FindTelegrafConfigs(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -828,6 +877,7 @@ func FindTelegrafConfigs(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -845,16 +895,19 @@ func FindTelegrafConfigs(
}, },
}, },
args: args{ args: args{
filter: platform.UserResourceMappingFilter{ filter: platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(threeID), UserID: MustIDBase16(threeID),
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
UserType: platform.Owner, UserType: platform.Owner,
}, },
}, },
},
wants: wants{ wants: wants{
telegrafConfigs: []*platform.TelegrafConfig{ telegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -865,6 +918,94 @@ func FindTelegrafConfigs(
}, },
}, },
}, },
{
name: "find owners and restrict by organization",
fields: TelegrafConfigFields{
UserResourceMappings: []*platform.UserResourceMapping{
{
ResourceID: MustIDBase16(oneID),
Resource: platform.TelegrafsResource,
UserID: MustIDBase16(threeID),
UserType: platform.Owner,
},
{
ResourceID: MustIDBase16(twoID),
Resource: platform.TelegrafsResource,
UserID: MustIDBase16(threeID),
UserType: platform.Member,
},
{
ResourceID: MustIDBase16(fourID),
Resource: platform.TelegrafsResource,
UserID: MustIDBase16(threeID),
UserType: platform.Owner,
},
},
TelegrafConfigs: []*platform.TelegrafConfig{
{
ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1",
Plugins: []platform.TelegrafPlugin{
{
Config: &inputs.CPUStats{},
},
},
},
{
ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2",
Plugins: []platform.TelegrafPlugin{
{
Comment: "comment1",
Config: &inputs.File{
Files: []string{"f1", "f2"},
},
},
{
Comment: "comment2",
Config: &inputs.MemStats{},
},
},
},
{
ID: MustIDBase16(fourID),
OrganizationID: MustIDBase16(oneID),
Name: "tc3",
Plugins: []platform.TelegrafPlugin{
{
Config: &inputs.CPUStats{},
},
},
},
},
},
args: args{
filter: platform.TelegrafConfigFilter{
OrganizationID: idPtr(MustIDBase16(oneID)),
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(threeID),
Resource: platform.TelegrafsResource,
UserType: platform.Owner,
},
},
},
wants: wants{
telegrafConfigs: []*platform.TelegrafConfig{
{
ID: MustIDBase16(fourID),
OrganizationID: MustIDBase16(oneID),
Name: "tc3",
Plugins: []platform.TelegrafPlugin{
{
Config: &inputs.CPUStats{},
},
},
},
},
},
},
{ {
name: "find nothing", name: "find nothing",
fields: TelegrafConfigFields{ fields: TelegrafConfigFields{
@ -885,6 +1026,7 @@ func FindTelegrafConfigs(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(threeID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -894,6 +1036,7 @@ func FindTelegrafConfigs(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -911,11 +1054,13 @@ func FindTelegrafConfigs(
}, },
}, },
args: args{ args: args{
filter: platform.UserResourceMappingFilter{ filter: platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: MustIDBase16(fourID), UserID: MustIDBase16(fourID),
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
}, },
}, },
},
wants: wants{ wants: wants{
err: &platform.Error{ err: &platform.Error{
Code: platform.ENotFound, Code: platform.ENotFound,
@ -978,6 +1123,7 @@ func UpdateTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -987,6 +1133,7 @@ func UpdateTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1035,6 +1182,7 @@ func UpdateTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1044,6 +1192,7 @@ func UpdateTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1064,6 +1213,7 @@ func UpdateTelegrafConfig(
userID: MustIDBase16(fourID), userID: MustIDBase16(fourID),
id: MustIDBase16(twoID), id: MustIDBase16(twoID),
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
OrganizationID: MustIDBase16(oneID), // notice this get ignored - ie., resulting TelegrafConfig will have OrganizationID equal to fourID
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1080,6 +1230,7 @@ func UpdateTelegrafConfig(
wants: wants{ wants: wants{
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1100,6 +1251,7 @@ func UpdateTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(oneID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1109,6 +1261,7 @@ func UpdateTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(oneID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1161,6 +1314,7 @@ func UpdateTelegrafConfig(
wants: wants{ wants: wants{
telegrafConfig: &platform.TelegrafConfig{ telegrafConfig: &platform.TelegrafConfig{
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(oneID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1249,6 +1403,7 @@ func DeleteTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1258,6 +1413,7 @@ func DeleteTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1300,6 +1456,7 @@ func DeleteTelegrafConfig(
telegrafConfigs: []*platform.TelegrafConfig{ telegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(fourID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1309,6 +1466,7 @@ func DeleteTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(fourID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1346,6 +1504,7 @@ func DeleteTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(threeID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1355,6 +1514,7 @@ func DeleteTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1396,6 +1556,7 @@ func DeleteTelegrafConfig(
telegrafConfigs: []*platform.TelegrafConfig{ telegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(threeID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1405,6 +1566,7 @@ func DeleteTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(threeID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1442,6 +1604,7 @@ func DeleteTelegrafConfig(
TelegrafConfigs: []*platform.TelegrafConfig{ TelegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1451,6 +1614,7 @@ func DeleteTelegrafConfig(
}, },
{ {
ID: MustIDBase16(twoID), ID: MustIDBase16(twoID),
OrganizationID: MustIDBase16(twoID),
Name: "tc2", Name: "tc2",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1483,6 +1647,7 @@ func DeleteTelegrafConfig(
telegrafConfigs: []*platform.TelegrafConfig{ telegrafConfigs: []*platform.TelegrafConfig{
{ {
ID: MustIDBase16(oneID), ID: MustIDBase16(oneID),
OrganizationID: MustIDBase16(twoID),
Name: "tc1", Name: "tc1",
Plugins: []platform.TelegrafPlugin{ Plugins: []platform.TelegrafPlugin{
{ {
@ -1509,10 +1674,13 @@ func DeleteTelegrafConfig(
t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err) t.Fatalf("expected error '%v' got '%v'", tt.wants.err, err)
} }
} }
tcs, n, err := s.FindTelegrafConfigs(ctx, platform.UserResourceMappingFilter{ filter := platform.TelegrafConfigFilter{
UserResourceMappingFilter: platform.UserResourceMappingFilter{
UserID: tt.args.userID, UserID: tt.args.userID,
Resource: platform.TelegrafsResource, Resource: platform.TelegrafsResource,
}) },
}
tcs, n, err := s.FindTelegrafConfigs(ctx, filter)
if err != nil && tt.wants.err == nil { if err != nil && tt.wants.err == nil {
t.Fatalf("expected errors to be nil got '%v'", err) t.Fatalf("expected errors to be nil got '%v'", err)
} }

View File

@ -29,6 +29,10 @@ func diffPlatformErrors(name string, actual, expected error, opPrefix string, t
} }
} }
func idPtr(id platform.ID) *platform.ID {
return &id
}
// MustIDBase16 is an helper to ensure a correct ID is built during testing. // MustIDBase16 is an helper to ensure a correct ID is built during testing.
func MustIDBase16(s string) platform.ID { func MustIDBase16(s string) platform.ID {
id, err := platform.IDFromString(s) id, err := platform.IDFromString(s)