-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add v1alpha RoleBinding e2e tests (#486)
## Motivation Extends e2e tests coverage for `v1alpha` `RoleBinding`.
- Loading branch information
1 parent
1a0e281
commit 8338531
Showing
8 changed files
with
188 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
# duration | ||
- apiVersion: n9/v1alpha | ||
kind: AlertSilence | ||
metadata: | ||
name: scheduled-maintenance-2024-05-01 | ||
name: incident-70 | ||
project: default | ||
spec: | ||
description: Scheduled maintenance alerts silence | ||
description: Alerts silenced for the duration of the active incident 70 | ||
slo: api-server-latency | ||
alertPolicy: | ||
name: fast-burn | ||
project: default | ||
period: | ||
startTime: 2024-05-01T12:00:00Z | ||
endTime: 2024-05-01T14:00:00Z | ||
duration: 4h | ||
# end time | ||
- apiVersion: n9/v1alpha | ||
kind: AlertSilence | ||
metadata: | ||
name: scheduled-maintenance-2024-05-02 | ||
name: incident-71 | ||
project: default | ||
spec: | ||
description: Scheduled maintenance alerts silence | ||
description: Alerts silenced until incident 71 is resolved | ||
slo: api-server-latency | ||
alertPolicy: | ||
name: fast-burn | ||
project: default | ||
period: | ||
startTime: 2024-05-02T12:00:00Z | ||
duration: 2h | ||
endTime: 2024-05-01T20:00:00Z | ||
# start and end time | ||
- apiVersion: n9/v1alpha | ||
kind: AlertSilence | ||
metadata: | ||
name: incident-70 | ||
name: scheduled-maintenance-2024-05-01 | ||
project: default | ||
spec: | ||
description: Alerts silenced for the duration of the active incident 70 | ||
description: Scheduled maintenance alerts silence | ||
slo: api-server-latency | ||
alertPolicy: | ||
name: fast-burn | ||
project: default | ||
period: | ||
duration: 4h | ||
startTime: 2024-05-01T12:00:00Z | ||
endTime: 2024-05-01T14:00:00Z | ||
# start time and duration | ||
- apiVersion: n9/v1alpha | ||
kind: AlertSilence | ||
metadata: | ||
name: incident-71 | ||
name: scheduled-maintenance-2024-05-02 | ||
project: default | ||
spec: | ||
description: Alerts silenced until incident 71 is resolved | ||
description: Scheduled maintenance alerts silence | ||
slo: api-server-latency | ||
alertPolicy: | ||
name: fast-burn | ||
project: default | ||
period: | ||
endTime: 2024-05-01T20:00:00Z | ||
startTime: 2024-05-02T12:00:00Z | ||
duration: 2h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
//go:build e2e_test | ||
|
||
package tests | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/nobl9/nobl9-go/manifest" | ||
v1alphaRoleBinding "github.com/nobl9/nobl9-go/manifest/v1alpha/rolebinding" | ||
"github.com/nobl9/nobl9-go/sdk" | ||
objectsV1 "github.com/nobl9/nobl9-go/sdk/endpoints/objects/v1" | ||
) | ||
|
||
func Test_Objects_V1_V1alpha_RoleBinding(t *testing.T) { | ||
t.Parallel() | ||
ctx := context.Background() | ||
|
||
project := generateV1alphaProject(t) | ||
v1Apply(t, ctx, []manifest.Object{project}) | ||
implicitBindings, err := client.Objects().V1().GetV1alphaRoleBindings(ctx, | ||
objectsV1.GetRoleBindingsRequest{Project: project.GetName()}) | ||
require.NoError(t, err) | ||
require.Len(t, implicitBindings, 1) | ||
implicitProjectBinding := implicitBindings[0] | ||
|
||
inputs := []v1alphaRoleBinding.RoleBinding{ | ||
v1alphaRoleBinding.New( | ||
v1alphaRoleBinding.Metadata{Name: generateName()}, | ||
v1alphaRoleBinding.Spec{ | ||
User: ptr(generateName()), | ||
RoleRef: "organization-blank", | ||
}, | ||
), | ||
v1alphaRoleBinding.New( | ||
v1alphaRoleBinding.Metadata{Name: generateName()}, | ||
v1alphaRoleBinding.Spec{ | ||
GroupRef: ptr(generateName()), | ||
RoleRef: "organization-blank", | ||
}, | ||
), | ||
v1alphaRoleBinding.New( | ||
v1alphaRoleBinding.Metadata{Name: generateName()}, | ||
v1alphaRoleBinding.Spec{ | ||
User: ptr(generateName()), | ||
RoleRef: "project-viewer", | ||
ProjectRef: project.GetName(), | ||
}, | ||
), | ||
v1alphaRoleBinding.New( | ||
v1alphaRoleBinding.Metadata{Name: generateName()}, | ||
v1alphaRoleBinding.Spec{ | ||
GroupRef: ptr(generateName()), | ||
RoleRef: "project-viewer", | ||
ProjectRef: project.GetName(), | ||
}, | ||
), | ||
v1alphaRoleBinding.New( | ||
v1alphaRoleBinding.Metadata{Name: generateName()}, | ||
v1alphaRoleBinding.Spec{ | ||
User: ptr(generateName()), | ||
RoleRef: "project-viewer", | ||
ProjectRef: defaultProject, | ||
}, | ||
), | ||
v1alphaRoleBinding.New( | ||
v1alphaRoleBinding.Metadata{Name: generateName()}, | ||
v1alphaRoleBinding.Spec{ | ||
GroupRef: ptr(generateName()), | ||
RoleRef: "project-viewer", | ||
ProjectRef: defaultProject, | ||
}, | ||
), | ||
} | ||
|
||
v1Apply(t, ctx, inputs) | ||
t.Cleanup(func() { | ||
// Organization role bindings cannot be deleted. | ||
filterOrganizationBindings := func(r v1alphaRoleBinding.RoleBinding) bool { | ||
return !strings.HasPrefix(r.Spec.RoleRef, "organization-") | ||
} | ||
v1Delete(t, ctx, filterSlice(inputs, filterOrganizationBindings)) | ||
}) | ||
|
||
filterTests := map[string]struct { | ||
request objectsV1.GetRoleBindingsRequest | ||
expected []v1alphaRoleBinding.RoleBinding | ||
returnsAll bool | ||
}{ | ||
"all": { | ||
request: objectsV1.GetRoleBindingsRequest{Project: sdk.ProjectsWildcard}, | ||
expected: inputs, | ||
returnsAll: true, | ||
}, | ||
"default project": { | ||
request: objectsV1.GetRoleBindingsRequest{}, | ||
expected: []v1alphaRoleBinding.RoleBinding{inputs[4], inputs[5]}, | ||
returnsAll: true, | ||
}, | ||
"filter by project": { | ||
request: objectsV1.GetRoleBindingsRequest{ | ||
Project: project.GetName(), | ||
}, | ||
expected: []v1alphaRoleBinding.RoleBinding{implicitProjectBinding, inputs[2], inputs[3]}, | ||
}, | ||
"filter by name": { | ||
request: objectsV1.GetRoleBindingsRequest{ | ||
Project: project.GetName(), | ||
Names: []string{inputs[2].Metadata.Name}, | ||
}, | ||
expected: []v1alphaRoleBinding.RoleBinding{inputs[2]}, | ||
}, | ||
} | ||
for name, test := range filterTests { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
actual, err := client.Objects().V1().GetV1alphaRoleBindings(ctx, test.request) | ||
require.NoError(t, err) | ||
if !test.returnsAll { | ||
require.Len(t, actual, len(test.expected)) | ||
} | ||
assertSubset(t, actual, test.expected, assertV1alphaRoleBindingsAreEqual) | ||
}) | ||
} | ||
} | ||
|
||
func assertV1alphaRoleBindingsAreEqual(t *testing.T, expected, actual v1alphaRoleBinding.RoleBinding) { | ||
t.Helper() | ||
assert.Equal(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters