gitlab.com/pidrakin/dotfiles-cli@v1.7.5/ssh_ultimate/user_test.go (about) 1 package ssh_ultimate 2 3 import ( 4 "github.com/kevinburke/ssh_config" 5 "github.com/stretchr/testify/assert" 6 "gitlab.com/pidrakin/go/tests" 7 "testing" 8 ) 9 10 func userSSHConfig() string { 11 return ` 12 Host * 13 User root 14 ` 15 } 16 17 func TestParseUser(t *testing.T) { 18 Prepare(t, userSSHConfig, func(t *testing.T, sshConfig *ssh_config.Config) { 19 t.Run("without ssh config: override", func(t *testing.T) { 20 user, err := parseUser(nil, "foobar", "alice") 21 tests.AssertNoError(t, err) 22 assert.Equal(t, "alice", user) 23 }) 24 25 t.Run("without ssh config: default", func(t *testing.T) { 26 user, err := parseUser(nil, "foobar", "") 27 tests.AssertNoError(t, err) 28 assert.NotEmpty(t, user) 29 }) 30 31 t.Run("with config", func(t *testing.T) { 32 user, err := parseUser(sshConfig, "foobar", "") 33 tests.AssertNoError(t, err) 34 assert.Equal(t, "root", user) 35 }) 36 }) 37 }