Skip to content
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
47 changes: 47 additions & 0 deletions internal/config/guard_policy_normalize_repos_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNormalizeAllowOnlyReposValue(t *testing.T) {
tests := []struct {
name string
input interface{}
want interface{}
wantErr string
}{
{"all string", "all", "all", ""},
{"public mixed case with whitespace", " PuBlic ", "public", ""},
{"invalid string", "owner/repo", nil, "must be 'all' or 'public'"},
{"empty string", "", nil, "must be 'all' or 'public'"},
{"interface slice normalized and sorted", []interface{}{"Octo/Repo", " acme/* "}, []string{"acme/*", "octo/repo"}, ""},
{"string slice normalized and sorted", []string{"Zed/*", "abc/def"}, []string{"abc/def", "zed/*"}, ""},
{"prefix wildcard", []interface{}{"owner/re*"}, []string{"owner/re*"}, ""},
{"empty interface slice", []interface{}{}, nil, "at least one scope"},
{"empty string slice", []string{}, nil, "at least one scope"},
{"non-string entry", []interface{}{42}, nil, "must be strings"},
{"duplicates after normalization", []interface{}{"Owner/Repo", "owner/repo"}, nil, "duplicates"},
{"all combined with others", []interface{}{"all", "owner/repo"}, nil, "cannot be combined"},
{"invalid scope", []interface{}{"not-a-scope"}, nil, "is invalid"},
{"blank entry", []interface{}{" "}, nil, "repos"},
{"nil", nil, nil, "must be 'all', 'public', or an array"},
{"unsupported type", 123, nil, "must be 'all', 'public', or an array"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := NormalizeAllowOnlyReposValue(tt.input)
if tt.wantErr != "" {
require.Error(t, err)
assert.Contains(t, err.Error(), tt.wantErr)
assert.Nil(t, got)
return
}
require.NoError(t, err)
assert.Equal(t, tt.want, got)
})
}
}
Loading