MCPcopy Index your code
hub / github.com/cortesi/devd / TestReverseProxy

Function TestReverseProxy

inject/inject_test.go:37–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestReverseProxy(t *testing.T) {
38 var sniffTests = []struct {
39 snifflen int
40 marker string
41 payload string
42
43 src string
44 result string
45 }{
46 {0, "mark", "inject", "nomatch", "nomatch"},
47 {1, "mark", "inject", "nomatch", "nomatch"},
48 {10, "mark", "inject", "nomatch", "nomatch"},
49 {100, "mark", "inject", "nomatch", "nomatch"},
50 {10, "mark", "inject", "imarki", "iinjectmarki"},
51 {5, "mark", "inject", "imarki", "iinjectmarki"},
52 {4, "mark", "inject", "marki", "injectmarki"},
53 {10, "mark", "inject", "imark", "iinjectmark"},
54 {5, "mark", "inject", "imark", "iinjectmark"},
55 {100, "mark", "inject", "imark", "iinjectmark"},
56 }
57 for i, tt := range sniffTests {
58 ci := CopyInject{
59 Within: tt.snifflen,
60 ContentType: "text/html",
61 Marker: regexp.MustCompile(tt.marker),
62 Payload: []byte(tt.payload),
63 }
64 found, dst, err := inject(ci, tt.src, "text/html")
65
66 // Sanity checkss
67 if err != nil {
68 t.Errorf("Test %d, unexpected error:\n%s\n", i, err)
69 }
70 if found && strings.Index(dst, tt.payload) == -1 {
71 t.Errorf(
72 "Test %d, payload not found.", i,
73 )
74 }
75 var expected int
76 if found {
77 expected = len(tt.src) + len(tt.payload)
78 } else {
79 expected = len(tt.src)
80 }
81 if len(dst) != expected {
82 t.Errorf(
83 "Test %d, expected %d bytes copied, found %d", i, len(dst), expected,
84 )
85 }
86 if dst != tt.result {
87 t.Errorf("Test %d, expected '%v', got '%v'", i, tt.result, dst)
88 }
89
90 // Idempotence
91 found, dst2, err := inject(ci, dst, "text/html")
92 if err != nil {
93 t.Errorf("Test %d, unexpected error:\n%s\n", i, err)
94 }

Callers

nothing calls this directly

Calls 1

injectFunction · 0.85

Tested by

no test coverage detected