Skip to content

Commit

Permalink
F/fix test suite (#3)
Browse files Browse the repository at this point in the history
* chore: add debug

* chore: print error saving file

* chore: add path 2 log

* chore: add rename err

* fix: only rename once

* chore: return error when readFile() and copyFile() returns error
  • Loading branch information
vinhphuctadang authored and saniales committed Jan 19, 2023
1 parent 71aa501 commit ec608cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 7 additions & 2 deletions mongobin/getOrDownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func init() {
// at the given URL. If the URL has not yet been downloaded, it's downloaded
// and saved the the cache. If it has been downloaded, the existing mongod
// path is returned.
/*
Flow: URL (download url) -> check existence
exist: return mongo path
non-exist: http download -> save bin/mongod
*/
func GetOrDownloadMongod(urlStr string, cachePath string, logger *memongolog.Logger) (string, error) {
dirname, dirErr := directoryNameForURL(urlStr)
if dirErr != nil {
Expand Down Expand Up @@ -156,11 +161,11 @@ func saveFile(mongodPath string, tarReader *tar.Reader, logger *memongolog.Logge

content, err := Afs.ReadFile(mongodTmpFile.Name())
if err != nil {
fmt.Println("ERROR:", err)
return fmt.Errorf("read file err: %w", err)
}
_, copyErr := mongodFile.Write(content)
if copyErr != nil {
fmt.Errorf("error copying mongod binary from %s to %s: %s", mongodTmpFile.Name(), mongodPath, copyErr)
return fmt.Errorf("error copying mongod binary from %s to %s: %w", mongodTmpFile.Name(), mongodPath, copyErr)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions mongobin/getOrDownload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ func TestGetOrDownload(t *testing.T) {
}

func TestGetOrDownloadDifferentFilesystems(t *testing.T) {

FS := afero.NewMemMapFs() // afero.NewOsFs()

ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := mockAfero.NewMockFs(ctrl)

m.EXPECT().Rename(gomock.Any(), gomock.Any()).Return(&os.LinkError{"rename", "oldname", "newname", errors.New("rename error")}).Times(2)
m.EXPECT().Rename(gomock.Any(), gomock.Any()).Return(&os.LinkError{"rename", "oldname", "newname", errors.New("rename error")}).Times(1)

// General mock faking :)
m.EXPECT().Mkdir(gomock.Any(), gomock.Any()).DoAndReturn(func(dir string, perm fs.FileMode) error { return FS.Mkdir(dir, perm) }).AnyTimes()
Expand Down

0 comments on commit ec608cc

Please sign in to comment.