MCPcopy
hub / github.com/google/mtail / TestExamplePrograms

Function TestExamplePrograms

internal/mtail/examples_integration_test.go:88–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestExamplePrograms(t *testing.T) {
89 testutil.SkipIfShort(t)
90 for _, tc := range exampleProgramTests {
91 tc := tc
92 t.Run(fmt.Sprintf("%s on %s", tc.programfile, tc.logfile),
93 testutil.TimeoutTest(exampleTimeout, func(t *testing.T) { //nolint:thelper
94 ctx, cancel := context.WithCancel(context.Background())
95 waker, _ := waker.NewTest(ctx, 0, "waker") // oneshot means we should never need to wake the stream
96 store := metrics.NewStore()
97 programFile := filepath.Join("../..", tc.programfile)
98 mtail, err := mtail.New(ctx, store, mtail.ProgramPath(programFile), mtail.LogPathPatterns(tc.logfile), mtail.OneShot, mtail.OmitMetricSource, mtail.DumpAstTypes, mtail.DumpBytecode, mtail.LogPatternPollWaker(waker), mtail.LogstreamPollWaker(waker))
99 testutil.FatalIfErr(t, err)
100
101 var wg sync.WaitGroup
102 wg.Add(1)
103 go func() {
104 defer wg.Done()
105 testutil.FatalIfErr(t, mtail.Run())
106 }()
107 // Oneshot mode means we can wait for shutdown before cancelling.
108 wg.Wait()
109 cancel()
110
111 g, err := os.Open(tc.goldenfile)
112 testutil.FatalIfErr(t, err)
113 defer g.Close()
114
115 goldenStore := golden.ReadTestData(g, tc.programfile)
116
117 var storeList metrics.MetricSlice
118 store.Range(func(m *metrics.Metric) error {
119 storeList = append(storeList, m)
120 return nil
121 })
122
123 testutil.ExpectNoDiff(t, goldenStore, storeList, testutil.SortSlices(metrics.Less), testutil.IgnoreUnexported(metrics.Metric{}, sync.RWMutex{}, datum.String{}))
124 }))
125 }
126}
127
128// This test only compiles examples, but has coverage over all examples
129// provided. This ensures we ship at least syntactically correct examples.

Callers

nothing calls this directly

Calls 15

RangeMethod · 0.95
SkipIfShortFunction · 0.92
TimeoutTestFunction · 0.92
NewStoreFunction · 0.92
NewFunction · 0.92
ProgramPathTypeAlias · 0.92
LogPathPatternsFunction · 0.92
LogPatternPollWakerFunction · 0.92
LogstreamPollWakerFunction · 0.92
FatalIfErrFunction · 0.92
ReadTestDataFunction · 0.92
ExpectNoDiffFunction · 0.92

Tested by

no test coverage detected