Adds hundreds of unit/integration/e2e tests, fixes WS bcrypt auth, config merge, fleet analytics, agent schedule/log tail, and documents stale PROBLEMS items. Updates PROBLEMS.md, README, and test scripts; ignores local spread-kits and coverage dirs.
90 lines
2.0 KiB
Go
90 lines
2.0 KiB
Go
//go:build windows
|
|
|
|
package client
|
|
|
|
import "testing"
|
|
|
|
func TestJSONBoolHelpers(t *testing.T) {
|
|
m := map[string]interface{}{
|
|
"b": true,
|
|
"s": "true",
|
|
"n": "1",
|
|
"x": "false",
|
|
}
|
|
if v := jsonBool(m, "b"); v == nil || !*v {
|
|
t.Fatal("bool true")
|
|
}
|
|
if v := jsonBool(m, "s"); v == nil || !*v {
|
|
t.Fatal("string true")
|
|
}
|
|
if v := jsonBool(m, "n"); v == nil || !*v {
|
|
t.Fatal("numeric string true")
|
|
}
|
|
if v := jsonBool(m, "x"); v == nil || *v {
|
|
t.Fatal("string false")
|
|
}
|
|
if jsonBool(m, "missing") != nil {
|
|
t.Fatal("missing key")
|
|
}
|
|
}
|
|
|
|
func TestJSONIntHelpers(t *testing.T) {
|
|
m := map[string]interface{}{
|
|
"f": float64(42),
|
|
"i": 7,
|
|
"s": "99",
|
|
"b": "nope",
|
|
}
|
|
if v := jsonInt(m, "f"); v == nil || *v != 42 {
|
|
t.Fatalf("float64: %v", v)
|
|
}
|
|
if v := jsonInt(m, "i"); v == nil || *v != 7 {
|
|
t.Fatalf("int: %v", v)
|
|
}
|
|
if v := jsonInt(m, "s"); v == nil || *v != 99 {
|
|
t.Fatalf("string int: %v", v)
|
|
}
|
|
if jsonInt(m, "b") != nil {
|
|
t.Fatal("invalid string int")
|
|
}
|
|
}
|
|
|
|
func TestJSONStringHelpers(t *testing.T) {
|
|
m := map[string]interface{}{"ok": "value", "empty": ""}
|
|
if v := jsonString(m, "ok"); v == nil || *v != "value" {
|
|
t.Fatalf("string: %v", v)
|
|
}
|
|
if jsonString(m, "empty") != nil {
|
|
t.Fatal("empty string omitted")
|
|
}
|
|
}
|
|
|
|
func TestJSONStringSliceHelpers(t *testing.T) {
|
|
m := map[string]interface{}{
|
|
"one": "defender",
|
|
"multi": []interface{}{"a", "", "b"},
|
|
}
|
|
if got := jsonStringSlice(m, "one"); len(got) != 1 || got[0] != "defender" {
|
|
t.Fatalf("single: %v", got)
|
|
}
|
|
if got := jsonStringSlice(m, "multi"); len(got) != 2 || got[0] != "a" || got[1] != "b" {
|
|
t.Fatalf("multi: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestJSONServiceSlice(t *testing.T) {
|
|
m := map[string]interface{}{
|
|
"services": []interface{}{
|
|
map[string]interface{}{
|
|
"name": "WinDefend",
|
|
"status": "running",
|
|
"start_type": "auto",
|
|
},
|
|
},
|
|
}
|
|
svcs := jsonServiceSlice(m, "services")
|
|
if len(svcs) != 1 || svcs[0].Name != "WinDefend" || svcs[0].Status != "running" {
|
|
t.Fatalf("services: %+v", svcs)
|
|
}
|
|
}
|