(tc models.TestCase, logger *zap.Logger)
| 124 | } |
| 125 | |
| 126 | func EncodeTestcase(tc models.TestCase, logger *zap.Logger) (*yaml.NetworkTrafficDoc, error) { |
| 127 | logger.Debug("Starting test case encoding", |
| 128 | zap.String("kind", string(tc.Kind)), |
| 129 | zap.String("name", tc.Name)) |
| 130 | |
| 131 | doc := &yaml.NetworkTrafficDoc{ |
| 132 | Version: tc.Version, |
| 133 | Kind: tc.Kind, |
| 134 | Name: tc.Name, |
| 135 | LastUpdated: tc.LastUpdated, |
| 136 | } |
| 137 | |
| 138 | var noise map[string][]string |
| 139 | switch tc.Kind { |
| 140 | case models.HTTP: |
| 141 | logger.Debug("Encoding HTTP test case") |
| 142 | doc.Curl = tc.Curl |
| 143 | |
| 144 | // find noisy fields only for HTTP responses |
| 145 | m, err := FlattenHTTPResponse(pkg.ToHTTPHeader(tc.HTTPResp.Header), tc.HTTPResp.Body) |
| 146 | if err != nil { |
| 147 | msg := "error in flattening http response" |
| 148 | utils.LogError(logger, err, msg) |
| 149 | } |
| 150 | noise = tc.Noise |
| 151 | |
| 152 | noiseFieldsFound := FindNoisyFields(m, func(_ string, vals []string) bool { |
| 153 | // check if k is date |
| 154 | for _, v := range vals { |
| 155 | if pkg.IsTime(v) { |
| 156 | return true |
| 157 | } |
| 158 | } |
| 159 | // maybe we need to concatenate the values |
| 160 | return pkg.IsTime(strings.Join(vals, ", ")) |
| 161 | }) |
| 162 | |
| 163 | for _, v := range noiseFieldsFound { |
| 164 | noise[v] = []string{} |
| 165 | } |
| 166 | |
| 167 | httpSchema := models.HTTPSchema{ |
| 168 | Request: tc.HTTPReq, |
| 169 | Response: tc.HTTPResp, |
| 170 | Created: tc.Created, |
| 171 | AppPort: tc.AppPort, |
| 172 | // need to check here for type here as well as push in other custom assertions |
| 173 | Assertions: func() map[models.AssertionType]interface{} { |
| 174 | a := map[models.AssertionType]interface{}{} |
| 175 | for k, v := range tc.Assertions { |
| 176 | a[k] = v |
| 177 | } |
| 178 | |
| 179 | if len(noise) > 0 { |
| 180 | a[models.NoiseAssertion] = noise |
| 181 | } |
| 182 | |
| 183 | // Optionally add other custom assertions if needed here |
no test coverage detected