Skip to content

Commit

Permalink
print http response and fix mongo version
Browse files Browse the repository at this point in the history
  • Loading branch information
theleeeo committed Dec 21, 2023
1 parent b846744 commit 3640168
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
15 changes: 0 additions & 15 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path"
"runtime"
"strconv"
"strings"
"time"

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

func parseMongoMajorVersion(version string) int {
strParts := strings.Split(version, ".")
if len(strParts) == 0 {
return 0
}

maj, err := strconv.Atoi(strParts[0])
if err != nil {
return 0
}

return maj
}

func getFreePort() (int, error) {
// Based on: https://github.com/phayes/freeport/blob/master/freeport.go
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
Expand Down
6 changes: 3 additions & 3 deletions mongobin/downloadSpec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mongobin

import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -213,7 +213,7 @@ func detectOSName(mongoVersion []int) string {

// We control etcRedhatRelease
//nolint:gosec
redhatRelease, redhatReleaseErr := ioutil.ReadFile(EtcRedhatRelease)
redhatRelease, redhatReleaseErr := os.ReadFile(EtcRedhatRelease)
if redhatReleaseErr == nil {
return osNameFromRedhatRelease(string(redhatRelease))
}
Expand Down Expand Up @@ -273,7 +273,7 @@ func osNameFromOsRelease(osRelease map[string]string, mongoVersion []int) string
return ""
}
func osNameFromUbuntuRelease(majorVersion int, mongoVersion []int) string {
if majorVersion >= 22 && versionGTE(mongoVersion, []int{4, 0, 1}) {
if majorVersion >= 22 && versionGTE(mongoVersion, []int{6, 0, 4}) {
return "ubuntu2204"
}
if majorVersion >= 20 && versionGTE(mongoVersion, []int{4, 0, 1}) {
Expand Down
7 changes: 6 additions & 1 deletion mongobin/getOrDownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func GetOrDownloadMongod(urlStr string, cachePath string, logger *memongolog.Log
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("HTTP request failed with status code %d", resp.StatusCode)
}

tgzTempFile, tmpFileErr := Afs.TempFile("", "")
if tmpFileErr != nil {
return "", fmt.Errorf("error creating temp file for tarball: %s", tmpFileErr)
Expand All @@ -85,8 +89,9 @@ func GetOrDownloadMongod(urlStr string, cachePath string, logger *memongolog.Log
// Extract mongod
gzReader, gzErr := gzip.NewReader(tgzTempFile)
if gzErr != nil {
return "", fmt.Errorf("error intializing gzip reader from %s: %w, %s", tgzTempFile.Name(), gzErr, urlStr)
return "", fmt.Errorf("error initializing gzip reader from %s: %w, %s", tgzTempFile.Name(), gzErr, urlStr)
}
defer gzReader.Close()

tarReader := tar.NewReader(gzReader)
for {
Expand Down

0 comments on commit 3640168

Please sign in to comment.