New returns an instantiated Command as well as a context populated with mocked values for the command. All mock/fakes have been minimally configured to induce a successful call to the command.
(t *testing.T, cmd string, args ...string)
| 45 | // values for the command. All mock/fakes have been minimally configured to |
| 46 | // induce a successful call to the command. |
| 47 | func New(t *testing.T, cmd string, args ...string) (context.Context, *cobra.Command) { |
| 48 | t.Helper() |
| 49 | |
| 50 | var ( |
| 51 | execer = NewFakeExecer() |
| 52 | fs = xunixfake.NewMemFS() |
| 53 | mnt = &mount.FakeMounter{} |
| 54 | client = NewFakeDockerClient() |
| 55 | iface = GetNetLink(t) |
| 56 | ctx = ctx(t, fs, execer, mnt, client) |
| 57 | ) |
| 58 | |
| 59 | root := cli.Root() |
| 60 | // This is the one thing that isn't really mocked for the tests. |
| 61 | // I cringe at the thought of introducing yet another mock so |
| 62 | // let's avoid it for now. |
| 63 | // If a consumer sets the ethlink arg it should overwrite our |
| 64 | // default we set here. |
| 65 | args = append([]string{cmd, "--ethlink=" + iface.Attrs().Name, "--no-startup-log"}, args...) |
| 66 | root.SetArgs(args) |
| 67 | |
| 68 | FakeSysboxManagerReady(t, fs) |
| 69 | FakeCPUGroups(t, fs, "1234", "5678") |
| 70 | |
| 71 | return ctx, root |
| 72 | } |
| 73 | |
| 74 | func ctx(t *testing.T, fs xunix.FS, ex xunix.Execer, mnt mount.Interface, client dockerutil.Client) context.Context { |
| 75 | t.Helper() |