add bad test for freed.create

This commit is contained in:
Joel Wetzell
2026-03-16 19:59:02 -05:00
parent 2d74e14387
commit c7d407d507

View File

@@ -116,22 +116,454 @@ func TestGoodFreeDCreate(t *testing.T) {
}
func TestBadFreeDCreate(t *testing.T) {
packetEncoder := processor.FreeDCreate{}
tests := []struct {
name string
params map[string]any
payload any
errorString string
}{}
}{
{
name: "missing id",
params: map[string]any{
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create id error: not found",
},
{
name: "missing pan",
params: map[string]any{
"id": "1",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create pan error: not found",
},
{
name: "missing tilt",
params: map[string]any{
"id": "1",
"pan": "180",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create tilt error: not found",
},
{
name: "missing roll",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create roll error: not found",
},
{
name: "missing posX",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create posX error: not found",
},
{
name: "missing posY",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create posY error: not found",
},
{
name: "missing posZ",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create posZ error: not found",
},
{
name: "missing zoom",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"focus": "263430",
},
errorString: "freed.create zoom error: not found",
},
{
name: "missing focus",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
},
errorString: "freed.create focus error: not found",
},
{
name: "id not string",
params: map[string]any{
"id": 1,
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create id error: not a string",
payload: nil,
},
{
name: "pan not string",
params: map[string]any{
"id": "1",
"pan": 180,
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create pan error: not a string",
payload: nil,
},
{
name: "tilt not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": 90,
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create tilt error: not a string",
payload: nil,
},
{
name: "roll not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": -180,
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create roll error: not a string",
payload: nil,
},
{
name: "posX not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": 131069,
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create posX error: not a string",
payload: nil,
},
{
name: "posY not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": 131070,
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create posY error: not a string",
payload: nil,
},
{
name: "posZ not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": 131071,
"zoom": "66051",
"focus": "263430",
},
errorString: "freed.create posZ error: not a string",
payload: nil,
},
{
name: "zoom not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": 66051,
"focus": "263430",
},
errorString: "freed.create zoom error: not a string",
payload: nil,
},
{
name: "focus not string",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": 263430,
},
errorString: "freed.create focus error: not a string",
payload: nil,
},
{
name: "id template error",
params: map[string]any{
"id": "{{.Unknown}}",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: id:1:2: executing \"id\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "pan template error",
params: map[string]any{
"id": "1",
"pan": "{{.Unknown}}",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: pan:1:2: executing \"pan\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "tilt template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "{{.Unknown}}",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: tilt:1:2: executing \"tilt\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "roll template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "{{.Unknown}}",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: roll:1:2: executing \"roll\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "posX template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "{{.Unknown}}",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: posX:1:2: executing \"posX\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "posY template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "{{.Unknown}}",
"posZ": "131071",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: posY:1:2: executing \"posY\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "posZ template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "{{.Unknown}}",
"zoom": "66051",
"focus": "263430",
},
errorString: "template: posZ:1:2: executing \"posZ\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "zoom template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "{{.Unknown}}",
"focus": "263430",
},
errorString: "template: zoom:1:2: executing \"zoom\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
{
name: "focus template error",
params: map[string]any{
"id": "1",
"pan": "180",
"tilt": "90",
"roll": "-180",
"posX": "131069",
"posY": "131070",
"posZ": "131071",
"zoom": "66051",
"focus": "{{.Unknown}}",
},
errorString: "template: focus:1:2: executing \"focus\" at <.Unknown>: can't evaluate field Unknown in type common.WrappedPayload",
payload: nil,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
registration, ok := processor.ProcessorRegistry["freed.create"]
if !ok {
t.Fatalf("freed.create processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "freed.create",
Params: test.params,
})
if err != nil {
if test.errorString != err.Error() {
t.Fatalf("string.create got error '%s', expected '%s'", err.Error(), test.errorString)
}
return
}
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("freed.create expected to fail but succeeded, got: %v", got)
}
if err.Error() != test.errorString {
t.Fatalf("freed.create got error '%s', expected '%s'", err.Error(), test.errorString)
}