MCPcopy
hub / github.com/cilium/cilium / TestScript

Function TestScript

contrib/examples/script/example_test.go:17–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestScript(t *testing.T) {
18 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
19 t.Cleanup(cancel)
20
21 // Run the test scripts in parallel using the [ctx] defined above. This
22 // gives each test script 5 seconds to complete. Without a context that
23 // times out we would default to the 10 minute test timeout. Choose a
24 // timeout that is suitable large for your tests that has enough buffer,
25 // but still makes a good feedback cycle when working on new or failing
26 // tests.
27 scripttest.Test(
28 t,
29 ctx,
30 func(t testing.TB, args []string) *script.Engine {
31 log := hivetest.Logger(t)
32
33 // Define a "test" hive consisting of the cell being tested and
34 // its dependencies.
35 h := hive.New(
36 Cell,
37
38 // dependencies of [Cell] would go here.
39 )
40 flags := pflag.NewFlagSet("", pflag.ContinueOnError)
41 h.RegisterFlags(flags)
42
43 // Gather the commands provided by cells in the hive [h] and add
44 // the default script commands.
45 cmds, err := h.ScriptCommands(log)
46 require.NoError(t, err, "ScriptCommands")
47 maps.Insert(cmds, maps.All(script.DefaultCmds()))
48
49 // Stop the hive automatically after the test is complete.
50 t.Cleanup(func() { h.Stop(log, context.Background()) })
51
52 // Return the engine for executing the test scripts.
53 return &script.Engine{
54 Cmds: cmds,
55 }
56 },
57 []string{}, // Environment
58 "testdata/*.txtar", // Scripts to execute
59 )
60}

Callers

nothing calls this directly

Calls 7

CleanupMethod · 0.65
LoggerMethod · 0.65
NewMethod · 0.65
InsertMethod · 0.65
AllMethod · 0.65
StopMethod · 0.65
WithTimeoutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…