(t *testing.T)
| 2601 | } |
| 2602 | |
| 2603 | func TestSetContext(t *testing.T) { |
| 2604 | type key struct{} |
| 2605 | val := "foobar" |
| 2606 | root := &Command{ |
| 2607 | Use: "root", |
| 2608 | Run: func(cmd *Command, args []string) { |
| 2609 | key := cmd.Context().Value(key{}) |
| 2610 | got, ok := key.(string) |
| 2611 | if !ok { |
| 2612 | t.Error("key not found in context") |
| 2613 | } |
| 2614 | if got != val { |
| 2615 | t.Errorf("Expected value: \n %v\nGot:\n %v\n", val, got) |
| 2616 | } |
| 2617 | }, |
| 2618 | } |
| 2619 | |
| 2620 | ctx := context.WithValue(context.Background(), key{}, val) |
| 2621 | root.SetContext(ctx) |
| 2622 | err := root.Execute() |
| 2623 | if err != nil { |
| 2624 | t.Error(err) |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | func TestSetContextPreRun(t *testing.T) { |
| 2629 | type key struct{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…