add another 100 tests (thank you claude for making these I ain't coming up with this much shit to test)
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExtractTimestamp_Int64(t *testing.T) {
|
||||
var ts int64 = 1700000000000
|
||||
if got := extractTimestamp(ts); got != ts {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Uint64(t *testing.T) {
|
||||
var ts uint64 = 1700000000000
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Uint64Overflow(t *testing.T) {
|
||||
// Values exceeding max int64 should return 0
|
||||
var ts uint64 = math.MaxUint64
|
||||
if got := extractTimestamp(ts); got != 0 {
|
||||
t.Fatalf("expected 0 for overflow, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Uint32(t *testing.T) {
|
||||
var ts uint32 = 170000
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Uint16(t *testing.T) {
|
||||
var ts uint16 = 1234
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Uint8(t *testing.T) {
|
||||
var ts uint8 = 42
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Int32(t *testing.T) {
|
||||
var ts int32 = 12345678
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Int16(t *testing.T) {
|
||||
var ts int16 = 9999
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Int8(t *testing.T) {
|
||||
var ts int8 = 127
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Int(t *testing.T) {
|
||||
var ts int = 1700000000
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Float64(t *testing.T) {
|
||||
var ts float64 = 1700000000000.0
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", int64(ts), got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Float32(t *testing.T) {
|
||||
var ts float32 = 170000.0
|
||||
if got := extractTimestamp(ts); got != int64(ts) {
|
||||
t.Fatalf("expected %d, got %d", int64(ts), got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_JsonNumber(t *testing.T) {
|
||||
n := json.Number("1700000000000")
|
||||
if got := extractTimestamp(n); got != 1700000000000 {
|
||||
t.Fatalf("expected 1700000000000, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_InvalidJsonNumber(t *testing.T) {
|
||||
n := json.Number("not-a-number")
|
||||
if got := extractTimestamp(n); got != 0 {
|
||||
t.Fatalf("expected 0 for invalid json.Number, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_String(t *testing.T) {
|
||||
if got := extractTimestamp("hello"); got != 0 {
|
||||
t.Fatalf("expected 0 for string, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Nil(t *testing.T) {
|
||||
if got := extractTimestamp(nil); got != 0 {
|
||||
t.Fatalf("expected 0 for nil, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Bool(t *testing.T) {
|
||||
if got := extractTimestamp(true); got != 0 {
|
||||
t.Fatalf("expected 0 for bool, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Zero(t *testing.T) {
|
||||
if got := extractTimestamp(int64(0)); got != 0 {
|
||||
t.Fatalf("expected 0, got %d", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractTimestamp_Negative(t *testing.T) {
|
||||
var ts int64 = -100
|
||||
if got := extractTimestamp(ts); got != ts {
|
||||
t.Fatalf("expected %d, got %d", ts, got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseCommandArgs_EmptyInput(t *testing.T) {
|
||||
result := parseCommandArgs("")
|
||||
if len(result) != 0 {
|
||||
t.Fatalf("expected empty slice, got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_WhitespaceOnly(t *testing.T) {
|
||||
result := parseCommandArgs(" \t ")
|
||||
if len(result) != 0 {
|
||||
t.Fatalf("expected empty slice, got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_SimpleWords(t *testing.T) {
|
||||
result := parseCommandArgs("hello world foo")
|
||||
if len(result) != 3 || result[0] != "hello" || result[1] != "world" || result[2] != "foo" {
|
||||
t.Fatalf("expected [hello world foo], got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_DoubleQuotes(t *testing.T) {
|
||||
result := parseCommandArgs(`echo "hello world" done`)
|
||||
if len(result) != 3 || result[0] != "echo" || result[1] != "hello world" || result[2] != "done" {
|
||||
t.Fatalf("expected [echo, hello world, done], got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_SingleQuotes(t *testing.T) {
|
||||
result := parseCommandArgs(`echo 'hello world' done`)
|
||||
if len(result) != 3 || result[0] != "echo" || result[1] != "hello world" || result[2] != "done" {
|
||||
t.Fatalf("expected [echo, hello world, done], got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_EscapedChars(t *testing.T) {
|
||||
result := parseCommandArgs(`hello\ world`)
|
||||
if len(result) != 1 || result[0] != "hello world" {
|
||||
t.Fatalf("expected [hello world], got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_MixedQuotes(t *testing.T) {
|
||||
result := parseCommandArgs(`cmd "arg one" 'arg two' plain`)
|
||||
if len(result) != 4 {
|
||||
t.Fatalf("expected 4 args, got %d: %v", len(result), result)
|
||||
}
|
||||
if result[0] != "cmd" || result[1] != "arg one" || result[2] != "arg two" || result[3] != "plain" {
|
||||
t.Fatalf("got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_TrailingEscape(t *testing.T) {
|
||||
result := parseCommandArgs(`hello\`)
|
||||
if len(result) != 1 || result[0] != `hello\` {
|
||||
t.Fatalf("expected [hello\\], got %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_EmptyQuotes(t *testing.T) {
|
||||
result := parseCommandArgs(`a "" b`)
|
||||
if len(result) != 3 || result[1] != "" {
|
||||
if len(result) == 2 && result[0] == "a" && result[1] == "b" {
|
||||
return
|
||||
}
|
||||
t.Logf("result: %v (len %d)", result, len(result))
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseCommandArgs_PathWithSpaces(t *testing.T) {
|
||||
result := parseCommandArgs(`"C:\\Program Files\\App\\app.exe" --flag value`)
|
||||
if len(result) != 3 {
|
||||
t.Fatalf("expected 3 args, got %d: %v", len(result), result)
|
||||
}
|
||||
if result[0] != `C:\Program Files\App\app.exe` {
|
||||
t.Fatalf("path not preserved: %s", result[0])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestStreamInterval_Default(t *testing.T) {
|
||||
os.Unsetenv("TEST_FPS_VAR")
|
||||
interval, fps := streamInterval("TEST_FPS_VAR", 30)
|
||||
if fps != 30 {
|
||||
t.Fatalf("expected fps=30, got %d", fps)
|
||||
}
|
||||
expected := time.Second / 30
|
||||
if interval != expected {
|
||||
t.Fatalf("expected interval=%v, got %v", expected, interval)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_CustomValue(t *testing.T) {
|
||||
os.Setenv("TEST_FPS_VAR2", "60")
|
||||
defer os.Unsetenv("TEST_FPS_VAR2")
|
||||
|
||||
interval, fps := streamInterval("TEST_FPS_VAR2", 30)
|
||||
if fps != 60 {
|
||||
t.Fatalf("expected fps=60, got %d", fps)
|
||||
}
|
||||
expected := time.Second / 60
|
||||
if interval != expected {
|
||||
t.Fatalf("expected interval=%v, got %v", expected, interval)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_InvalidFallsBack(t *testing.T) {
|
||||
os.Setenv("TEST_FPS_BAD", "abc")
|
||||
defer os.Unsetenv("TEST_FPS_BAD")
|
||||
|
||||
_, fps := streamInterval("TEST_FPS_BAD", 25)
|
||||
if fps != 25 {
|
||||
t.Fatalf("expected default fps=25 on bad input, got %d", fps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_ZeroFallsBack(t *testing.T) {
|
||||
os.Setenv("TEST_FPS_ZERO", "0")
|
||||
defer os.Unsetenv("TEST_FPS_ZERO")
|
||||
|
||||
_, fps := streamInterval("TEST_FPS_ZERO", 15)
|
||||
if fps != 15 {
|
||||
t.Fatalf("expected fps=15 when env=0, got %d", fps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_NegativeFallsBack(t *testing.T) {
|
||||
os.Setenv("TEST_FPS_NEG", "-5")
|
||||
defer os.Unsetenv("TEST_FPS_NEG")
|
||||
|
||||
_, fps := streamInterval("TEST_FPS_NEG", 20)
|
||||
if fps != 20 {
|
||||
t.Fatalf("expected fps=20 on negative input, got %d", fps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_ClampMax(t *testing.T) {
|
||||
os.Setenv("TEST_FPS_HIGH", "9999")
|
||||
defer os.Unsetenv("TEST_FPS_HIGH")
|
||||
|
||||
_, fps := streamInterval("TEST_FPS_HIGH", 30)
|
||||
if fps != 1000 {
|
||||
t.Fatalf("expected clamped fps=1000, got %d", fps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_ClampMin(t *testing.T) {
|
||||
os.Unsetenv("TEST_FPS_MIN")
|
||||
_, fps := streamInterval("TEST_FPS_MIN", 0)
|
||||
if fps != 1 {
|
||||
t.Fatalf("expected clamped fps=1, got %d", fps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamInterval_WhitespaceEnv(t *testing.T) {
|
||||
os.Setenv("TEST_FPS_WS", " 45 ")
|
||||
defer os.Unsetenv("TEST_FPS_WS")
|
||||
|
||||
_, fps := streamInterval("TEST_FPS_WS", 30)
|
||||
if fps != 45 {
|
||||
t.Fatalf("expected fps=45 (trimmed whitespace), got %d", fps)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user