MCPcopy
hub / github.com/spf13/cobra / TestSetContextPreRunOverwrite

Function TestSetContextPreRunOverwrite

command_test.go:2654–2673  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2652}
2653
2654func TestSetContextPreRunOverwrite(t *testing.T) {
2655 type key struct{}
2656 val := "blah"
2657 root := &Command{
2658 Use: "root",
2659 Run: func(cmd *Command, args []string) {
2660 key := cmd.Context().Value(key{})
2661 _, ok := key.(string)
2662 if ok {
2663 t.Error("key found in context when not expected")
2664 }
2665 },
2666 }
2667 ctx := context.WithValue(context.Background(), key{}, val)
2668 root.SetContext(ctx)
2669 err := root.ExecuteContext(context.Background())
2670 if err != nil {
2671 t.Error(err)
2672 }
2673}
2674
2675func TestSetContextPersistentPreRun(t *testing.T) {
2676 type key struct{}

Callers

nothing calls this directly

Calls 4

SetContextMethod · 0.95
ExecuteContextMethod · 0.95
ContextMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…