| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package api
- import (
- "context"
- "errors"
- "testing"
- )
- func TestOwnerCapabilitiesAndErrors(t *testing.T) {
- if (Owner{}).Valid() {
- t.Fatal("empty owner accepted")
- }
- if !(Owner{EnvironmentID: "e", ThreadID: "t", RunID: "r"}).Valid() {
- t.Fatal("valid owner rejected")
- }
- c := Capabilities{Features: map[string]Capability{"ok": {Status: "supported"}, "partial": {Status: "degraded"}}}
- if !c.Supports("ok") || c.Supports("partial") || c.Supports("missing") {
- t.Fatal("capability status ignored")
- }
- if Err("CODE", "message").Error() != "CODE: message" {
- t.Fatal("error code missing")
- }
- if !errors.Is(&Error{Code: "BROWSER_TIMEOUT", Message: "expired", Cause: context.DeadlineExceeded}, context.DeadlineExceeded) {
- t.Fatal("transport cause lost")
- }
- }
- func TestActionValidation(t *testing.T) {
- for _, action := range []string{"click", "hover", "fill", "type", "select", "check", "uncheck", "press", "scroll"} {
- r := ActionRequest{SnapshotID: "s", Ref: "e1", Action: action}
- if action == "press" {
- r.Value = "Enter"
- }
- if action == "scroll" {
- r.Value = "down"
- }
- if e := ValidateAction(r); e != nil {
- t.Errorf("%s: %v", action, e)
- }
- }
- for _, r := range []ActionRequest{{}, {SnapshotID: "s", Ref: "e", Action: "execute"}, {SnapshotID: "s", Ref: "e", Action: "press", Value: "RunShell"}, {SnapshotID: "s", Ref: "e", Action: "scroll", Value: "sideways"}, {SnapshotID: "s", Ref: "e", Action: "fill", Value: string(make([]byte, 16385))}} {
- if ValidateAction(r) == nil {
- t.Errorf("invalid action accepted: %q", r.Action)
- }
- }
- }
|