TestJSONRoundTripHTTPSpec checks that HTTP spec data survives JSON round-trip.
(t *testing.T)
| 147 | |
| 148 | // TestJSONRoundTripHTTPSpec checks that HTTP spec data survives JSON round-trip. |
| 149 | func TestJSONRoundTripHTTPSpec(t *testing.T) { |
| 150 | original := buildHTTPDoc() |
| 151 | |
| 152 | data, err := MarshalDoc(FormatJSON, original) |
| 153 | if err != nil { |
| 154 | t.Fatalf("MarshalDoc error: %v", err) |
| 155 | } |
| 156 | |
| 157 | decoded, err := UnmarshalDoc(FormatJSON, data) |
| 158 | if err != nil { |
| 159 | t.Fatalf("UnmarshalDoc error: %v", err) |
| 160 | } |
| 161 | |
| 162 | // Decode spec from the round-tripped document |
| 163 | var httpSpec models.HTTPSchema |
| 164 | if err := decoded.Spec.Decode(&httpSpec); err != nil { |
| 165 | t.Fatalf("Spec.Decode error: %v", err) |
| 166 | } |
| 167 | |
| 168 | if httpSpec.Request.URL != "http://localhost:8080/api" { |
| 169 | t.Errorf("request URL = %q", httpSpec.Request.URL) |
| 170 | } |
| 171 | if string(httpSpec.Request.Method) != "GET" { |
| 172 | t.Errorf("request method = %q", httpSpec.Request.Method) |
| 173 | } |
| 174 | if httpSpec.Response.StatusCode != 200 { |
| 175 | t.Errorf("response status = %d", httpSpec.Response.StatusCode) |
| 176 | } |
| 177 | if httpSpec.Response.Body != `{"result":"ok"}` { |
| 178 | t.Errorf("response body = %q", httpSpec.Response.Body) |
| 179 | } |
| 180 | if httpSpec.Created != 1700000000 { |
| 181 | t.Errorf("created = %d, want 1700000000", httpSpec.Created) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // TestMarshalGenericJSON tests MarshalGeneric with a struct that has json tags. |
| 186 | func TestMarshalGenericJSON(t *testing.T) { |
nothing calls this directly
no test coverage detected