MCPcopy Create free account
hub / github.com/conforma/cli / TestTrackerAddKeepsOrder

Function TestTrackerAddKeepsOrder

internal/tracker/tracker_gen_test.go:34–138  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func 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

Callers

nothing calls this directly

Calls 3

newTrackerFunction · 0.85
addTrustedTaskRecordMethod · 0.80
OutputMethod · 0.80

Tested by

no test coverage detected