syft/internal/config/registry_test.go
Alex Goodman 9fb79bfa2e
dont append registry auth if potentially empty
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2021-04-14 10:28:21 -04:00

60 lines
862 B
Go

package config
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHasNonEmptyCredentials(t *testing.T) {
tests := []struct {
auth, username, password, token string
expected bool
}{
{
"", "", "", "",
false,
},
{
"auth", "", "", "",
false,
},
{
"auth", "user", "", "",
false,
},
{
"auth", "", "pass", "",
false,
},
{
"auth", "", "pass", "tok",
true,
},
{
"auth", "user", "", "tok",
true,
},
{
"auth", "", "", "tok",
true,
},
{
"auth", "user", "pass", "tok",
true,
},
{
"auth", "user", "pass", "",
true,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
assert.Equal(t, test.expected, hasNonEmptyCredentials(test.auth, test.username, test.password, test.token))
})
}
}