mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* Add scaffolding * Move migration * Add endpoints for gitauth * Add configuration files and tests! * Update typesgen * Convert configuration format for git auth * Fix unclosed database conn * Add overriding VS Code configuration * Fix Git screen * Write VS Code special configuration if providers exist * Enable automatic cloning from VS Code * Add tests for gitaskpass * Fix feature visibiliy * Add banner for too many configurations * Fix update loop for oauth token * Jon comments * Add deployment config page
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package gitauth_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/coderd/gitauth"
|
|
)
|
|
|
|
func TestCheckCommand(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Success", func(t *testing.T) {
|
|
t.Parallel()
|
|
valid := gitauth.CheckCommand([]string{"Username "}, []string{"GIT_PREFIX=/example"})
|
|
require.True(t, valid)
|
|
})
|
|
t.Run("Failure", func(t *testing.T) {
|
|
t.Parallel()
|
|
valid := gitauth.CheckCommand([]string{}, []string{})
|
|
require.False(t, valid)
|
|
})
|
|
}
|
|
|
|
func TestParse(t *testing.T) {
|
|
t.Parallel()
|
|
for _, tc := range []struct {
|
|
in string
|
|
wantUser string
|
|
wantHost string
|
|
}{
|
|
{
|
|
in: "Username for 'https://github.com': ",
|
|
wantUser: "",
|
|
wantHost: "https://github.com",
|
|
},
|
|
{
|
|
in: "Username for 'https://enterprise.github.com': ",
|
|
wantUser: "",
|
|
wantHost: "https://enterprise.github.com",
|
|
},
|
|
{
|
|
in: "Username for 'http://wow.io': ",
|
|
wantUser: "",
|
|
wantHost: "http://wow.io",
|
|
},
|
|
{
|
|
in: "Password for 'https://myuser@github.com': ",
|
|
wantUser: "myuser",
|
|
wantHost: "https://github.com",
|
|
},
|
|
{
|
|
in: "Password for 'https://myuser@enterprise.github.com': ",
|
|
wantUser: "myuser",
|
|
wantHost: "https://enterprise.github.com",
|
|
},
|
|
{
|
|
in: "Password for 'http://myuser@wow.io': ",
|
|
wantUser: "myuser",
|
|
wantHost: "http://wow.io",
|
|
},
|
|
} {
|
|
tc := tc
|
|
t.Run(tc.in, func(t *testing.T) {
|
|
t.Parallel()
|
|
user, host, err := gitauth.ParseAskpass(tc.in)
|
|
require.NoError(t, err)
|
|
require.Equal(t, tc.wantUser, user)
|
|
require.Equal(t, tc.wantHost, host)
|
|
})
|
|
}
|
|
}
|