(test api.HTTPRequestTest, variables map[string]string)
| 114 | } |
| 115 | |
| 116 | func prettyPrintHTTPTest(test api.HTTPRequestTest, variables map[string]string) string { |
| 117 | if test.StatusCode != nil { |
| 118 | return fmt.Sprintf("Expecting status code: %d", *test.StatusCode) |
| 119 | } |
| 120 | if test.BodyContains != nil { |
| 121 | interpolated := InterpolateVariables(*test.BodyContains, variables) |
| 122 | return fmt.Sprintf("Expecting body to contain: %s", interpolated) |
| 123 | } |
| 124 | if test.BodyContainsNone != nil { |
| 125 | interpolated := InterpolateVariables(*test.BodyContainsNone, variables) |
| 126 | return fmt.Sprintf("Expecting JSON body to not contain: %s", interpolated) |
| 127 | } |
| 128 | if test.HeadersContain != nil { |
| 129 | interpolatedKey := InterpolateVariables(test.HeadersContain.Key, variables) |
| 130 | interpolatedValue := InterpolateVariables(test.HeadersContain.Value, variables) |
| 131 | return fmt.Sprintf("Expecting headers to contain: '%s: %v'", interpolatedKey, interpolatedValue) |
| 132 | } |
| 133 | if test.TrailersContain != nil { |
| 134 | interpolatedKey := InterpolateVariables(test.TrailersContain.Key, variables) |
| 135 | interpolatedValue := InterpolateVariables(test.TrailersContain.Value, variables) |
| 136 | return fmt.Sprintf("Expecting trailers to contain: '%s: %v'", interpolatedKey, interpolatedValue) |
| 137 | } |
| 138 | if test.JSONValue != nil { |
| 139 | var val any |
| 140 | switch { |
| 141 | case test.JSONValue.IntValue != nil: |
| 142 | val = *test.JSONValue.IntValue |
| 143 | case test.JSONValue.StringValue != nil: |
| 144 | val = *test.JSONValue.StringValue |
| 145 | case test.JSONValue.BoolValue != nil: |
| 146 | val = *test.JSONValue.BoolValue |
| 147 | } |
| 148 | |
| 149 | var op string |
| 150 | switch test.JSONValue.Operator { |
| 151 | case api.OpEquals: |
| 152 | op = "to be equal to" |
| 153 | case api.OpGreaterThan: |
| 154 | op = "to be greater than" |
| 155 | case api.OpContains: |
| 156 | op = "contains" |
| 157 | case api.OpNotContains: |
| 158 | op = "to not contain" |
| 159 | } |
| 160 | |
| 161 | expecting := fmt.Sprintf("Expecting JSON at %v %s %v", test.JSONValue.Path, op, val) |
| 162 | return InterpolateVariables(expecting, variables) |
| 163 | } |
| 164 | return "" |
| 165 | } |
| 166 | |
| 167 | // Return a capped string representation of the response body. |
| 168 | // |
no test coverage detected