Skip to content

Commit

Permalink
Fixed failed lint errors, unit and e2e test failures
Browse files Browse the repository at this point in the history
Signed-off-by: anandf <anjoseph@redhat.com>
  • Loading branch information
anandf committed Sep 26, 2024
1 parent ffec02b commit 8fd6bae
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,15 +578,15 @@ func deriveServiceAccountToImpersonate(project *v1alpha1.AppProject, application
for _, item := range project.Spec.DestinationServiceAccounts {
dstServerMatched, err := glob.MatchWithError(item.Server, application.Spec.Destination.Server)
if err != nil {
return "", fmt.Errorf("invalid glob pattern for destination server: %v", err)
return "", fmt.Errorf("invalid glob pattern for destination server: %w", err)
}
dstNamespaceMatched, err := glob.MatchWithError(item.Namespace, application.Spec.Destination.Namespace)
if err != nil {
return "", fmt.Errorf("invalid glob pattern for destination namespace: %v", err)
return "", fmt.Errorf("invalid glob pattern for destination namespace: %w", err)
}
if dstServerMatched && dstNamespaceMatched {
if strings.Trim(item.DefaultServiceAccount, " ") == "" || strings.ContainsAny(item.DefaultServiceAccount, "!*[]\\/") {
return "", fmt.Errorf("default service account contains invalid chars %s", item.DefaultServiceAccount)
if strings.Trim(item.DefaultServiceAccount, " ") == "" || strings.ContainsAny(item.DefaultServiceAccount, serviceAccountDisallowedCharSet) {
return "", fmt.Errorf("default service account contains invalid chars '%s'", item.DefaultServiceAccount)
} else if strings.Contains(item.DefaultServiceAccount, ":") {
// service account is specified along with its namespace.
return fmt.Sprintf("system:serviceaccount:%s", item.DefaultServiceAccount), nil
Expand Down
2 changes: 1 addition & 1 deletion controller/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ func TestSyncWithImpersonate(t *testing.T) {
t.Run("sync with impersonation and empty service account match", func(t *testing.T) {
// given app sync impersonation feature is enabled with an application referring a project matching service account that is an empty string
f := setup(true, test.FakeDestNamespace, "")
opMessage := "failed to find a matching service account to impersonate: default service account cannot be an empty string"
opMessage := "failed to find a matching service account to impersonate: default service account contains invalid chars ''"

opState := &v1alpha1.OperationState{
Operation: v1alpha1.Operation{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/app/consequences.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Consequences) Expect(e Expectation) *Consequences {
return c
}

// ExpectConsistently will continously evaluate a condition, and it must be true each time it is evaluated, otherwise the test is failed. The condition will be repeatedly evaluated until 'expirationDuration' is met, waiting 'waitDuration' after each success.
// ExpectConsistently will continuously evaluate a condition, and it must be true each time it is evaluated, otherwise the test is failed. The condition will be repeatedly evaluated until 'expirationDuration' is met, waiting 'waitDuration' after each success.
func (c *Consequences) ExpectConsistently(e Expectation, waitDuration time.Duration, expirationDuration time.Duration) *Consequences {
// this invocation makes sure this func is not reported as the cause of the failure - we are a "test helper"
c.context.t.Helper()
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/project_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func TestAddProjectDestinationServiceAccount(t *testing.T) {
"test-sa",
)
require.Error(t, err)
assert.Contains(t, err.Error(), "server has an invalid format, '!*'")
assert.Contains(t, err.Error(), "server has an invalid format, '!abc'")

// Given, an existing project,
// When, a default destination service account with negation glob pattern for namespace is added,
Expand Down Expand Up @@ -765,7 +765,7 @@ func TestAddProjectDestinationServiceAccount(t *testing.T) {
"test\\sa",
)
require.Error(t, err)
assert.Contains(t, err.Error(), "defaultServiceAccount has an invalid format, 'test\\sa'")
assert.Contains(t, err.Error(), "defaultServiceAccount has an invalid format, 'test\\\\sa'")

// Given, an existing project,
// When, a default destination service account with service account having forward slash char is added,
Expand Down

0 comments on commit 8fd6bae

Please sign in to comment.