(t *testing.T)
| 102 | } |
| 103 | |
| 104 | func 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 | } |
nothing calls this directly
no test coverage detected