Skip to content

Commit 65ce3a7

Browse files
theleeeosaniales
authored andcommitted
print http response and fix mongo version
1 parent b846744 commit 65ce3a7

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

config.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"path"
99
"runtime"
1010
"strconv"
11-
"strings"
1211
"time"
1312

1413
"github.com/tryvium-travels/memongo/memongolog"
@@ -143,20 +142,6 @@ func (opts *Options) getOrDownloadBinPath() (string, error) {
143142
return binPath, nil
144143
}
145144

146-
func parseMongoMajorVersion(version string) int {
147-
strParts := strings.Split(version, ".")
148-
if len(strParts) == 0 {
149-
return 0
150-
}
151-
152-
maj, err := strconv.Atoi(strParts[0])
153-
if err != nil {
154-
return 0
155-
}
156-
157-
return maj
158-
}
159-
160145
func getFreePort() (int, error) {
161146
// Based on: https://github.com/phayes/freeport/blob/master/freeport.go
162147
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")

mongobin/downloadSpec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package mongobin
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"os"
66
"runtime"
77
"strconv"
88
"strings"
@@ -213,7 +213,7 @@ func detectOSName(mongoVersion []int) string {
213213

214214
// We control etcRedhatRelease
215215
//nolint:gosec
216-
redhatRelease, redhatReleaseErr := ioutil.ReadFile(EtcRedhatRelease)
216+
redhatRelease, redhatReleaseErr := os.ReadFile(EtcRedhatRelease)
217217
if redhatReleaseErr == nil {
218218
return osNameFromRedhatRelease(string(redhatRelease))
219219
}
@@ -273,7 +273,7 @@ func osNameFromOsRelease(osRelease map[string]string, mongoVersion []int) string
273273
return ""
274274
}
275275
func osNameFromUbuntuRelease(majorVersion int, mongoVersion []int) string {
276-
if majorVersion >= 22 && versionGTE(mongoVersion, []int{4, 0, 1}) {
276+
if majorVersion >= 22 && versionGTE(mongoVersion, []int{6, 0, 4}) {
277277
return "ubuntu2204"
278278
}
279279
if majorVersion >= 20 && versionGTE(mongoVersion, []int{4, 0, 1}) {

mongobin/getOrDownload.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func GetOrDownloadMongod(urlStr string, cachePath string, logger *memongolog.Log
6363
}
6464
defer resp.Body.Close()
6565

66+
if resp.StatusCode != http.StatusOK {
67+
return "", fmt.Errorf("HTTP request failed with status code %d", resp.StatusCode)
68+
}
69+
6670
tgzTempFile, tmpFileErr := Afs.TempFile("", "")
6771
if tmpFileErr != nil {
6872
return "", fmt.Errorf("error creating temp file for tarball: %s", tmpFileErr)
@@ -85,8 +89,9 @@ func GetOrDownloadMongod(urlStr string, cachePath string, logger *memongolog.Log
8589
// Extract mongod
8690
gzReader, gzErr := gzip.NewReader(tgzTempFile)
8791
if gzErr != nil {
88-
return "", fmt.Errorf("error intializing gzip reader from %s: %w, %s", tgzTempFile.Name(), gzErr, urlStr)
92+
return "", fmt.Errorf("error initializing gzip reader from %s: %w, %s", tgzTempFile.Name(), gzErr, urlStr)
8993
}
94+
defer gzReader.Close()
9095

9196
tarReader := tar.NewReader(gzReader)
9297
for {

0 commit comments

Comments
 (0)