(t *testing.T)
| 32 | ) |
| 33 | |
| 34 | func TestTrackerAddKeepsOrder(t *testing.T) { |
| 35 | parameters := gopter.DefaultTestParameters() |
| 36 | |
| 37 | // uncomment when test fails and set the seed to the printed value |
| 38 | // parameters.Rng.Seed(1234) |
| 39 | arbitraries := arbitrary.DefaultArbitraries() |
| 40 | |
| 41 | nonEmptyIdentifier := gen.Identifier().SuchThat(func(v string) bool { |
| 42 | return len(v) > 0 |
| 43 | }) |
| 44 | arbitraries.RegisterGen(gen.SliceOf( |
| 45 | gen.Struct(reflect.TypeOf(taskRecord{}), map[string]gopter.Gen{ |
| 46 | "Ref": gen.RegexMatch("^([[:alnum:]]+:)?[[:xdigit:]]+$"), |
| 47 | "EffectiveOn": gen.Time(), |
| 48 | "ExpiresOn": gen.PtrOf(gen.Time()), |
| 49 | "Tag": gen.Identifier(), |
| 50 | "Repository": nonEmptyIdentifier, |
| 51 | }))) |
| 52 | |
| 53 | properties := gopter.NewProperties(parameters) |
| 54 | |
| 55 | properties.Property("collections are sorted", arbitraries.ForAll( |
| 56 | func(records []taskRecord) bool { |
| 57 | tracker, err := newTracker(nil) |
| 58 | if err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | |
| 62 | for _, r := range records { |
| 63 | tracker.addTrustedTaskRecord(ociPrefix, r) |
| 64 | } |
| 65 | |
| 66 | raw, err := tracker.Output() |
| 67 | if err != nil { |
| 68 | panic(err) |
| 69 | } |
| 70 | |
| 71 | buff := bytes.NewBuffer(raw) |
| 72 | scanner := bufio.NewScanner(buff) |
| 73 | scanner.Split(bufio.ScanLines) |
| 74 | |
| 75 | // at this level of indentation, last string was |
| 76 | lastAt := map[int]string{} |
| 77 | lastLevel := 0 |
| 78 | for scanner.Scan() { |
| 79 | line := scanner.Text() |
| 80 | |
| 81 | // ignore blank lines or document separator lines |
| 82 | if line == "" || line == "---" { |
| 83 | continue |
| 84 | } |
| 85 | |
| 86 | if strings.HasPrefix(strings.TrimLeftFunc(line, unicode.IsSpace), "?") { |
| 87 | // complex key, next line is the value |
| 88 | _, line, _ = strings.Cut(line, "?") |
| 89 | scanner.Scan() |
| 90 | } |
| 91 |
nothing calls this directly
no test coverage detected