MCPcopy
hub / github.com/qustavo/httplab / TestLoadFromJSON

Function TestLoadFromJSON

response_test.go:137–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestLoadFromJSON(t *testing.T) {
138 rl := NewResponsesList()
139 require.NoError(t, rl.Load("./testdata/httplab.json"))
140
141 r := rl.Get("t1")
142 require.NotNil(t, r)
143 assert.Equal(t, 200, r.Status)
144 assert.Equal(t, time.Duration(1000), r.Delay)
145 assert.Equal(t, "value", r.Headers.Get("X-MyHeader"))
146
147 r.Body.Mode = BodyInput
148 assert.Equal(t, []byte("xxx"), r.Body.Payload())
149 assert.Equal(t, []byte("xxx"), r.Body.Info())
150
151 r.Body.Mode = BodyFile
152 assert.Equal(t, []byte("<html></html>"), r.Body.Payload())
153
154 t.Run("When config file is empty", func(t *testing.T) {
155 path := string(time.Now().UnixNano())
156 defer os.Remove(path)
157
158 require.NoError(t, rl.Load(path))
159 assert.Equal(t, 0, rl.Len())
160
161 // file has to be created
162 _, err := os.Stat(path)
163 assert.NoError(t, err)
164 })
165}
166
167func TestExpandPathExpansion(t *testing.T) {
168 defer os.Setenv("HOME", os.Getenv("HOME"))

Callers

nothing calls this directly

Calls 7

LoadMethod · 0.95
GetMethod · 0.95
LenMethod · 0.95
NewResponsesListFunction · 0.85
PayloadMethod · 0.80
GetMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected