Monorepo for Tangled tangled.org
2

Configure Feed

Select the types of activity you want to include in your feed.

at icy/ytnwlw 1.3 kB View raw
1package agentproto 2 3import ( 4 "bytes" 5 "encoding/binary" 6 "testing" 7 8 agentv1 "tangled.org/core/spindle/agentproto/gen" 9) 10 11func TestDecoderRejectsOversizedMessage(t *testing.T) { 12 var tooLarge bytes.Buffer 13 var header [4]byte 14 binary.BigEndian.PutUint32(header[:], MaxMessageBytes+1) 15 tooLarge.Write(header[:]) 16 17 _, err := NewDecoder(&tooLarge).Decode() 18 if err == nil { 19 t.Fatal("expected oversized message error") 20 } 21} 22 23func TestValidation(t *testing.T) { 24 // 1. Valid message (exactly one of the payload fields is set) 25 validMsg := &Message{ 26 Id: "test-1", 27 Hello: &agentv1.Hello{ 28 ProtocolVersion: 1, 29 AgentVersion: "1.0", 30 }, 31 } 32 if err := validator.Validate(validMsg); err != nil { 33 t.Fatalf("expected valid message to pass validation, got: %v", err) 34 } 35 36 // 2. Invalid message: zero payloads set 37 invalidZeroMsg := &Message{ 38 Id: "test-2", 39 } 40 if err := validator.Validate(invalidZeroMsg); err == nil { 41 t.Fatal("expected message with zero payloads to fail validation") 42 } 43 44 // 3. Invalid message: multiple payloads set 45 invalidMultiMsg := &Message{ 46 Id: "test-3", 47 Hello: &agentv1.Hello{ 48 ProtocolVersion: 1, 49 }, 50 Init: &agentv1.Init{ 51 JobId: "job-1", 52 }, 53 } 54 if err := validator.Validate(invalidMultiMsg); err == nil { 55 t.Fatal("expected message with multiple payloads to fail validation") 56 } 57}