mirror of https://github.com/coder/coder.git
57 lines
2.6 KiB
Go
57 lines
2.6 KiB
Go
package cli
|
|
|
|
import "testing"
|
|
|
|
func Test_resolveAgentAbsPath(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
type args struct {
|
|
workingDirectory string
|
|
relOrAbsPath string
|
|
agentOS string
|
|
local bool
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{"ok no args", args{}, "", false},
|
|
{"ok only working directory", args{workingDirectory: "/workdir"}, "/workdir", false},
|
|
{"ok with working directory and rel path", args{workingDirectory: "/workdir", relOrAbsPath: "my/path"}, "/workdir/my/path", false},
|
|
{"ok with working directory and abs path", args{workingDirectory: "/workdir", relOrAbsPath: "/my/path"}, "/my/path", false},
|
|
{"ok with no working directory and abs path", args{relOrAbsPath: "/my/path"}, "/my/path", false},
|
|
|
|
{"fail tilde", args{relOrAbsPath: "~"}, "", true},
|
|
{"fail tilde with working directory", args{workingDirectory: "/workdir", relOrAbsPath: "~"}, "", true},
|
|
{"fail tilde path", args{relOrAbsPath: "~/workdir"}, "", true},
|
|
{"fail tilde path with working directory", args{workingDirectory: "/workdir", relOrAbsPath: "~/workdir"}, "", true},
|
|
{"fail relative dot with no working directory", args{relOrAbsPath: "."}, "", true},
|
|
{"fail relative with no working directory", args{relOrAbsPath: "workdir"}, "", true},
|
|
|
|
{"ok with working directory and rel path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "my\\path", agentOS: "windows"}, "C:\\workdir\\my\\path", false},
|
|
{"ok with working directory and abs path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "C:\\my\\path", agentOS: "windows"}, "C:\\my\\path", false},
|
|
{"ok with no working directory and abs path on windows", args{relOrAbsPath: "C:\\my\\path", agentOS: "windows"}, "C:\\my\\path", false},
|
|
{"ok abs unix path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "/my/path", agentOS: "windows"}, "\\my\\path", false},
|
|
{"ok rel unix path on windows", args{workingDirectory: "C:\\workdir", relOrAbsPath: "my/path", agentOS: "windows"}, "C:\\workdir\\my\\path", false},
|
|
|
|
{"fail with no working directory and rel path on windows", args{relOrAbsPath: "my\\path", agentOS: "windows"}, "", true},
|
|
}
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, err := resolveAgentAbsPath(tt.args.workingDirectory, tt.args.relOrAbsPath, tt.args.agentOS, tt.args.local)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("resolveAgentAbsPath() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("resolveAgentAbsPath() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|