MCPcopy Index your code
hub / github.com/coder/envbox / New

Function New

cli/clitest/cli.go:47–72  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

45// values for the command. All mock/fakes have been minimally configured to
46// induce a successful call to the command.
47func 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
74func ctx(t *testing.T, fs xunix.FS, ex xunix.Execer, mnt mount.Interface, client dockerutil.Client) context.Context {
75 t.Helper()

Callers 1

TestDockerFunction · 0.92

Calls 8

NewMemFSFunction · 0.92
RootFunction · 0.92
NewFakeExecerFunction · 0.85
NewFakeDockerClientFunction · 0.85
GetNetLinkFunction · 0.85
ctxFunction · 0.85
FakeSysboxManagerReadyFunction · 0.85
FakeCPUGroupsFunction · 0.85

Tested by 1

TestDockerFunction · 0.74