mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
+32
-36
@@ -1,9 +1,7 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
@@ -30,12 +28,12 @@ func TestLogout(t *testing.T) {
|
||||
|
||||
logoutChan := make(chan struct{})
|
||||
logout, _ := clitest.New(t, "logout", "--global-config", string(config))
|
||||
logout.SetIn(pty.Input())
|
||||
logout.SetOut(pty.Output())
|
||||
logout.Stdin = pty.Input()
|
||||
logout.Stdout = pty.Output()
|
||||
|
||||
go func() {
|
||||
defer close(logoutChan)
|
||||
err := logout.Execute()
|
||||
err := logout.Run()
|
||||
assert.NoError(t, err)
|
||||
assert.NoFileExists(t, string(config.URL()))
|
||||
assert.NoFileExists(t, string(config.Session()))
|
||||
@@ -58,12 +56,12 @@ func TestLogout(t *testing.T) {
|
||||
|
||||
logoutChan := make(chan struct{})
|
||||
logout, _ := clitest.New(t, "logout", "--global-config", string(config), "-y")
|
||||
logout.SetIn(pty.Input())
|
||||
logout.SetOut(pty.Output())
|
||||
logout.Stdin = pty.Input()
|
||||
logout.Stdout = pty.Output()
|
||||
|
||||
go func() {
|
||||
defer close(logoutChan)
|
||||
err := logout.Execute()
|
||||
err := logout.Run()
|
||||
assert.NoError(t, err)
|
||||
assert.NoFileExists(t, string(config.URL()))
|
||||
assert.NoFileExists(t, string(config.Session()))
|
||||
@@ -88,13 +86,13 @@ func TestLogout(t *testing.T) {
|
||||
logoutChan := make(chan struct{})
|
||||
logout, _ := clitest.New(t, "logout", "--global-config", string(config))
|
||||
|
||||
logout.SetIn(pty.Input())
|
||||
logout.SetOut(pty.Output())
|
||||
logout.Stdin = pty.Input()
|
||||
logout.Stdout = pty.Output()
|
||||
|
||||
go func() {
|
||||
defer close(logoutChan)
|
||||
err := logout.Execute()
|
||||
assert.EqualError(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
|
||||
err := logout.Run()
|
||||
assert.ErrorContains(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
|
||||
}()
|
||||
|
||||
<-logoutChan
|
||||
@@ -115,13 +113,13 @@ func TestLogout(t *testing.T) {
|
||||
logoutChan := make(chan struct{})
|
||||
logout, _ := clitest.New(t, "logout", "--global-config", string(config))
|
||||
|
||||
logout.SetIn(pty.Input())
|
||||
logout.SetOut(pty.Output())
|
||||
logout.Stdin = pty.Input()
|
||||
logout.Stdout = pty.Output()
|
||||
|
||||
go func() {
|
||||
defer close(logoutChan)
|
||||
err = logout.Execute()
|
||||
assert.EqualError(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
|
||||
err = logout.Run()
|
||||
assert.ErrorContains(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
|
||||
}()
|
||||
|
||||
<-logoutChan
|
||||
@@ -166,29 +164,27 @@ func TestLogout(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
logoutChan := make(chan struct{})
|
||||
logout, _ := clitest.New(t, "logout", "--global-config", string(config))
|
||||
|
||||
logout.SetIn(pty.Input())
|
||||
logout.SetOut(pty.Output())
|
||||
logout.Stdin = pty.Input()
|
||||
logout.Stdout = pty.Output()
|
||||
|
||||
go func() {
|
||||
defer close(logoutChan)
|
||||
err := logout.Execute()
|
||||
assert.NotNil(t, err)
|
||||
var errorMessage string
|
||||
if runtime.GOOS == "windows" {
|
||||
errorMessage = "The process cannot access the file because it is being used by another process."
|
||||
} else {
|
||||
errorMessage = "permission denied"
|
||||
}
|
||||
errRegex := regexp.MustCompile(fmt.Sprintf("Failed to log out.\n\tremove URL file: .+: %s\n\tremove session file: .+: %s", errorMessage, errorMessage))
|
||||
assert.Regexp(t, errRegex, err.Error())
|
||||
pty.ExpectMatch("Are you sure you want to log out?")
|
||||
pty.WriteLine("yes")
|
||||
}()
|
||||
err = logout.Run()
|
||||
require.Error(t, err)
|
||||
|
||||
pty.ExpectMatch("Are you sure you want to log out?")
|
||||
pty.WriteLine("yes")
|
||||
<-logoutChan
|
||||
t.Logf("err: %v", err)
|
||||
|
||||
var wantError string
|
||||
if runtime.GOOS == "windows" {
|
||||
wantError = "The process cannot access the file because it is being used by another process."
|
||||
} else {
|
||||
wantError = "permission denied"
|
||||
}
|
||||
require.ErrorContains(t, err, wantError)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -200,11 +196,11 @@ func login(t *testing.T, pty *ptytest.PTY) config.Root {
|
||||
|
||||
doneChan := make(chan struct{})
|
||||
root, cfg := clitest.New(t, "login", "--force-tty", client.URL.String(), "--no-open")
|
||||
root.SetIn(pty.Input())
|
||||
root.SetOut(pty.Output())
|
||||
root.Stdin = pty.Input()
|
||||
root.Stdout = pty.Output()
|
||||
go func() {
|
||||
defer close(doneChan)
|
||||
err := root.Execute()
|
||||
err := root.Run()
|
||||
assert.NoError(t, err)
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user