package models import ( "fmt" "strings" ) // UncheckedLine is the report's line for test's background writes answered by // their kind (AnswerByKind): how many, where (inside its window, // or in the gap before it), and of which write kinds, in the order they were // first answered; "" when answers holds none. keploy test prints it as each // set ends, and keploy report under the test's status, from the test's // TestResult.Answers. // // post-url-1: 1 background write answered inside its window, unchecked (Mongo insert keploy.events) func UncheckedLine(test string, answers []UnmatchedCall) string { type where struct { n int kinds []string count map[string]int } inside, gap := &where{count: map[string]int{}}, &where{count: map[string]int{}} for _, a := range answers { if a.Answer != AnswerByKind { continue } w := inside if a.Kind == MissOutsideTest { w = gap } kind := a.WriteKind if kind == "" { kind = a.Protocol } w.n++ if w.count[kind] == 0 { w.kinds = append(w.kinds, kind) } w.count[kind]++ } var parts []string for _, w := range []struct { *where place string }{{inside, "inside its window"}, {gap, "in the gap before it"}} { if w.n == 0 { continue } kinds := make([]string, 0, len(w.kinds)) for _, k := range w.kinds { if c := w.count[k]; c > 1 { k = fmt.Sprintf("%s x%d", k, c) } kinds = append(kinds, k) } noun := "writes" if w.n == 1 { noun = "write" } parts = append(parts, fmt.Sprintf("%d background %s answered %s, unchecked (%s)", w.n, noun, w.place, strings.Join(kinds, ", "))) } if len(parts) == 0 { return "" } return test + ": " + strings.Join(parts, "; ") }