service_test.go raw
1 package ingestion
2
3 import (
4 "testing"
5 )
6
7 func TestResultConstructors(t *testing.T) {
8 t.Run("Accepted", func(t *testing.T) {
9 r := Accepted("msg")
10 if !r.Accepted || !r.Saved || r.RequireAuth || r.Error != nil {
11 t.Errorf("unexpected Accepted result: %+v", r)
12 }
13 if r.Message != "msg" {
14 t.Errorf("unexpected message: %s", r.Message)
15 }
16 })
17
18 t.Run("AcceptedNotSaved", func(t *testing.T) {
19 r := AcceptedNotSaved("msg")
20 if !r.Accepted || r.Saved || r.RequireAuth || r.Error != nil {
21 t.Error("unexpected AcceptedNotSaved result")
22 }
23 })
24
25 t.Run("Rejected", func(t *testing.T) {
26 r := Rejected("msg")
27 if r.Accepted || r.Saved || r.RequireAuth || r.Error != nil {
28 t.Error("unexpected Rejected result")
29 }
30 if r.Message != "msg" {
31 t.Errorf("unexpected message: %s", r.Message)
32 }
33 })
34
35 t.Run("AuthRequired", func(t *testing.T) {
36 r := AuthRequired("msg")
37 if r.Accepted || r.Saved || !r.RequireAuth || r.Error != nil {
38 t.Error("unexpected AuthRequired result")
39 }
40 })
41
42 t.Run("Errored", func(t *testing.T) {
43 err := &testError{msg: "test"}
44 r := Errored(err)
45 if r.Accepted || r.Saved || r.RequireAuth || r.Error != err {
46 t.Error("unexpected Errored result")
47 }
48 })
49 }
50
51 type testError struct {
52 msg string
53 }
54
55 func (e *testError) Error() string {
56 return e.msg
57 }
58
59 func TestConnectionContext(t *testing.T) {
60 ctx := &ConnectionContext{
61 AuthedPubkey: []byte{1, 2, 3},
62 Remote: "127.0.0.1:1234",
63 ConnectionID: "conn-123",
64 }
65
66 if string(ctx.AuthedPubkey) != string([]byte{1, 2, 3}) {
67 t.Error("AuthedPubkey mismatch")
68 }
69 if ctx.Remote != "127.0.0.1:1234" {
70 t.Error("Remote mismatch")
71 }
72 if ctx.ConnectionID != "conn-123" {
73 t.Error("ConnectionID mismatch")
74 }
75 }
76
77 func TestConfig(t *testing.T) {
78 cfg := Config{
79 SprocketChecker: nil,
80 SpecialKinds: nil,
81 }
82
83 // Just verify Config can be created
84 if cfg.SprocketChecker != nil {
85 t.Error("expected nil SprocketChecker")
86 }
87 }
88