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

Function TestFindFinch

pkg/path/finch_remote_test.go:104–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

102}
103
104func TestFindFinch(t *testing.T) {
105 t.Parallel()
106
107 testCases := []struct {
108 name string
109 mockSvc func(*mocks.FinchFinderDeps)
110 wantErr error
111 want Finch
112 }{
113 {
114 name: "happy path",
115 wantErr: nil,
116 want: Finch("/real"),
117 mockSvc: func(deps *mocks.FinchFinderDeps) {
118 deps.EXPECT().Executable().Return("/bin/path", nil)
119 deps.EXPECT().EvalSymlinks("/bin/path").Return("/real/bin/path", nil)
120 deps.EXPECT().FilePathJoin("/real/bin/path", "..", "..").Return("/real")
121 },
122 },
123 {
124 name: "failed to find the executable path",
125 want: "",
126 wantErr: fmt.Errorf("failed to locate the executable that starts this process: %w",
127 errors.New("failed to find executable path"),
128 ),
129 mockSvc: func(deps *mocks.FinchFinderDeps) {
130 deps.EXPECT().Executable().Return("", errors.New("failed to find executable path"))
131 },
132 },
133 {
134 name: "failed to find the real path of the executable",
135 want: "",
136 wantErr: fmt.Errorf("failed to find the real path of the executable: %w", errors.New("failed to find real path")),
137 mockSvc: func(deps *mocks.FinchFinderDeps) {
138 deps.EXPECT().Executable().Return("/bin/path", nil)
139 deps.EXPECT().EvalSymlinks("/bin/path").Return("", errors.New("failed to find real path"))
140 },
141 },
142 }
143
144 for _, tc := range testCases {
145 t.Run(tc.name, func(t *testing.T) {
146 t.Parallel()
147
148 ctrl := gomock.NewController(t)
149 deps := mocks.NewFinchFinderDeps(ctrl)
150 tc.mockSvc(deps)
151 got, err := FindFinch(deps)
152 assert.Equal(t, err, tc.wantErr)
153 assert.Equal(t, got, tc.want)
154 })
155 }
156}

Callers

nothing calls this directly

Calls 9

EXPECTMethod · 0.95
NewFinchFinderDepsFunction · 0.92
FindFinchFunction · 0.85
FinchTypeAlias · 0.70
ExecutableMethod · 0.65
EvalSymlinksMethod · 0.65
FilePathJoinMethod · 0.65
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected