50 lines
2.0 KiB
Go
50 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
|
|
)
|
|
|
|
func TestGlobalSocketAndCLIValueParsing_HP_CTL_11(t *testing.T) {
|
|
socket, args, err := globalSocket([]string{"--socket", filepath.Join(t.TempDir(), "rvbox.sock"), "run", "client", "echo"})
|
|
if err != nil || args[0] != "run" || socket == "" {
|
|
t.Fatalf("global socket = %q %#v, %v", socket, args, err)
|
|
}
|
|
if _, _, err := globalSocket([]string{"--socket", "relative.sock", "stat"}); err == nil {
|
|
t.Fatal("relative control socket accepted")
|
|
}
|
|
for input, want := range map[string]rvboxv1.ShellType{"sh": rvboxv1.ShellType_SHELL_SH, "bash": rvboxv1.ShellType_SHELL_BASH, "cmd": rvboxv1.ShellType_SHELL_CMD, "pwsh": rvboxv1.ShellType_SHELL_POWERSHELL, "": rvboxv1.ShellType_SHELL_TYPE_UNSPECIFIED} {
|
|
got, err := parseShell(input)
|
|
if err != nil || got != want {
|
|
t.Errorf("parseShell(%q) = %v, %v", input, got, err)
|
|
}
|
|
}
|
|
if _, err := parseProfile("unknown"); err == nil {
|
|
t.Fatal("unknown profile accepted")
|
|
}
|
|
if got := queueDuration(-time.Nanosecond); got != nil {
|
|
t.Fatal("negative queue duration was encoded")
|
|
}
|
|
if got := queueDuration(0); got == nil || got.AsDuration() != 0 {
|
|
t.Fatalf("zero queue duration = %v", got)
|
|
}
|
|
}
|
|
|
|
func TestGlobalRequestIDIsInjectedOnlyForMutations_HP_CTL_12(t *testing.T) {
|
|
t.Parallel()
|
|
id := "019c46f1-1d02-7000-8000-0000000000f1"
|
|
requestID, remaining, err := globalRequestID([]string{"--request-id", id, "run", "client", "echo"})
|
|
if err != nil || requestID != id || len(remaining) != 3 || remaining[0] != "run" {
|
|
t.Fatalf("global request ID = %q %#v %v", requestID, remaining, err)
|
|
}
|
|
if !readOnlyCommand([]string{"stat", "client"}) || !readOnlyCommand([]string{"storage", "incidents"}) || readOnlyCommand([]string{"run", "client", "echo"}) {
|
|
t.Fatal("read-only command classification is incorrect")
|
|
}
|
|
if _, _, err := globalRequestID([]string{"--request-id", id, "--request-id", id}); err == nil {
|
|
t.Fatal("duplicate global request IDs accepted")
|
|
}
|
|
}
|