Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove even more unused code #3952

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 0 additions & 97 deletions internal/controlplane/handlers_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package controlplane
import (
"context"
"fmt"
"reflect"
"strings"
"testing"

Expand All @@ -39,83 +38,6 @@ import (
minderv1 "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1"
)

func TestGetUnusedOldRuleStatuses(t *testing.T) {
t.Parallel()

tests := []struct {
name string
newRules profiles.RuleMapping
oldRules profiles.RuleMapping
wantUnusedRules profiles.RuleMapping
}{
{
name: "Unused rule in oldRules",
newRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name1"}: {Entity: minderv1.Entity_ENTITY_REPOSITORIES, RuleID: generateConsistentUUID(t, "Type1", "Name1")},
{RuleType: "Type2", RuleName: "Name2"}: {Entity: minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS, RuleID: generateConsistentUUID(t, "Type2", "Name2")},
},
oldRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name1"}: {Entity: minderv1.Entity_ENTITY_REPOSITORIES, RuleID: generateConsistentUUID(t, "Type1", "Name1")},
{RuleType: "Type3", RuleName: "Name3"}: {Entity: minderv1.Entity_ENTITY_ARTIFACTS, RuleID: generateConsistentUUID(t, "Type3", "Name3")},
},
wantUnusedRules: profiles.RuleMapping{
{RuleType: "Type3", RuleName: "Name3"}: {Entity: minderv1.Entity_ENTITY_ARTIFACTS, RuleID: generateConsistentUUID(t, "Type3", "Name3")},
},
},
{
name: "No unused rules in oldRules",
newRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name1"}: {Entity: minderv1.Entity_ENTITY_REPOSITORIES, RuleID: generateConsistentUUID(t, "Type1", "Name1")},
{RuleType: "Type2", RuleName: "Name2"}: {Entity: minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS, RuleID: generateConsistentUUID(t, "Type2", "Name2")},
},
oldRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name1"}: {Entity: minderv1.Entity_ENTITY_REPOSITORIES, RuleID: generateConsistentUUID(t, "Type1", "Name1")},
{RuleType: "Type2", RuleName: "Name2"}: {Entity: minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS, RuleID: generateConsistentUUID(t, "Type2", "Name2")},
},
wantUnusedRules: profiles.RuleMapping{},
},
{
name: "Unused rules with same rule type",
newRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name1"}: {Entity: minderv1.Entity_ENTITY_REPOSITORIES, RuleID: generateConsistentUUID(t, "Type1", "Name1")},
{RuleType: "Type1", RuleName: "Name2"}: {Entity: minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS, RuleID: generateConsistentUUID(t, "Type1", "Name2")},
},
oldRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name3"}: {Entity: minderv1.Entity_ENTITY_ARTIFACTS, RuleID: generateConsistentUUID(t, "Type1", "Name3")},
},
wantUnusedRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name3"}: {Entity: minderv1.Entity_ENTITY_ARTIFACTS, RuleID: generateConsistentUUID(t, "Type1", "Name3")},
},
},
{
name: "Unused old rules statuses with empty name",
newRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: "Name1"}: {Entity: minderv1.Entity_ENTITY_REPOSITORIES, RuleID: generateConsistentUUID(t, "Type1", "Name1")},
{RuleType: "Type1", RuleName: "Name2"}: {Entity: minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS, RuleID: generateConsistentUUID(t, "Type1", "Name2")},
},
oldRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: ""}: {Entity: minderv1.Entity_ENTITY_ARTIFACTS, RuleID: generateConsistentUUID(t, "Type1", "")},
{RuleType: "Type2", RuleName: ""}: {Entity: minderv1.Entity_ENTITY_PULL_REQUESTS, RuleID: generateConsistentUUID(t, "Type2", "")},
},
wantUnusedRules: profiles.RuleMapping{
{RuleType: "Type1", RuleName: ""}: {Entity: minderv1.Entity_ENTITY_ARTIFACTS, RuleID: generateConsistentUUID(t, "Type1", "")},
{RuleType: "Type2", RuleName: ""}: {Entity: minderv1.Entity_ENTITY_PULL_REQUESTS, RuleID: generateConsistentUUID(t, "Type2", "")},
},
},
}

for _, test := range tests {
test := test

t.Run(test.name, func(t *testing.T) {
t.Parallel()

gotUnusedRules := getUnusedOldRuleStatuses(test.newRules, test.oldRules)
require.True(t, reflect.DeepEqual(test.wantUnusedRules, gotUnusedRules))
})
}
}

//nolint:gocyclo
func TestCreateProfile(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -1166,22 +1088,3 @@ func TestPatchManagedProfile(t *testing.T) {
require.Contains(t, err.Error(), "attempted to edit a rule type or profile which belongs to a bundle")
require.Nil(t, patchedProfile)
}

func generateConsistentUUID(t *testing.T, ruleType, ruleName string) uuid.UUID {
t.Helper()
return uuid.NewSHA1(uuid.Nil, []byte(ruleType+ruleName))
}

func getUnusedOldRuleStatuses(
newRules, oldRules profiles.RuleMapping,
) profiles.RuleMapping {
unusedRuleStatuses := make(profiles.RuleMapping)

for ruleTypeAndName, rule := range oldRules {
if _, ok := newRules[ruleTypeAndName]; !ok {
unusedRuleStatuses[ruleTypeAndName] = rule
}
}

return unusedRuleStatuses
}
Loading