(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func 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. |
nothing calls this directly
no test coverage detected