MCPcopy
hub / github.com/runfinch/finch / TestXmain

Function TestXmain

cmd/finch/main_remote_test.go:41–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestXmain(t *testing.T) {
42 t.Parallel()
43
44 testCases := xmainTestCases{
45 {
46 name: "failed to find the finch path from path.FindFinch",
47 wantErr: fmt.Errorf("failed to find the installation path of Finch: %w",
48 fmt.Errorf("failed to locate the executable that starts this process: %w", errors.New("failed to find executable path")),
49 ),
50 mockSvc: func(
51 _ *mocks.Logger,
52 ffd *mocks.FinchFinderDeps,
53 _ afero.Fs,
54 _ *mocks.LoadSystemDeps,
55 _ *mocks.Memory,
56 ) {
57 ffd.EXPECT().Executable().Return("", errors.New("failed to find executable path"))
58 },
59 },
60 }
61
62 darwinTestCases := xmainTestCases{
63 {
64 name: "happy path",
65 wantErr: nil,
66 mockSvc: func(
67 _ *mocks.Logger,
68 ffd *mocks.FinchFinderDeps,
69 fs afero.Fs,
70 loadCfgDeps *mocks.LoadSystemDeps,
71 mem *mocks.Memory,
72 ) {
73 require.NoError(t, afero.WriteFile(fs, "/home/.finch/finch.yaml", []byte(remoteConfigStr), 0o600))
74
75 // called additionally in FinchRootDir
76 ffd.EXPECT().GetUserHome().Return("/home", nil).Times(2)
77 ffd.EXPECT().Executable().Return("/bin/path", nil)
78 ffd.EXPECT().EvalSymlinks("/bin/path").Return("/real/bin/path", nil)
79 ffd.EXPECT().FilePathJoin("/real/bin/path", "..", "..").Return("/real")
80 loadCfgDeps.EXPECT().NumCPU().Return(16)
81 // 12_884_901_888 == 12GiB
82 mem.EXPECT().TotalMemory().Return(uint64(12_884_901_888))
83 },
84 },
85 {
86 name: "failed to load finch config because of invalid YAML",
87 wantErr: fmt.Errorf("failed to load config: %w",
88 fmt.Errorf("failed to unmarshal config file: %w",
89 &yaml.TypeError{Errors: []string{"line 1: cannot unmarshal !!str `this is...` into config.Finch"}},
90 ),
91 ),
92 mockSvc: func(
93 _ *mocks.Logger,
94 ffd *mocks.FinchFinderDeps,
95 fs afero.Fs,
96 _ *mocks.LoadSystemDeps,
97 _ *mocks.Memory,
98 ) {

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewFinchFinderDepsFunction · 0.92
NewLoggerFunction · 0.92
NewLoadSystemDepsFunction · 0.92
NewMemoryFunction · 0.92
xmainFunction · 0.70
ErrorfMethod · 0.65
ExecutableMethod · 0.65
GetUserHomeMethod · 0.65
EvalSymlinksMethod · 0.65

Tested by

no test coverage detected