Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mongo version #34

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 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,10 +273,10 @@ 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}) {
if majorVersion >= 20 && versionGTE(mongoVersion, []int{4, 4, 0}) {
return "ubuntu2004"
}
if majorVersion >= 18 && versionGTE(mongoVersion, []int{4, 0, 1}) {
Expand Down
8 changes: 4 additions & 4 deletions mongobin/downloadSpec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestMakeDownloadSpec(t *testing.T) {
Platform: "linux",
SSLBuildNeeded: false,
Arch: "x86_64",
OSName: "ubuntu2204",
OSName: "ubuntu1804", // Ubuntu 22.04 is not supported by Mongo 4.0.5, so it falls back to Ubuntu 18.04
},
},
"ubuntu 20.04": {
Expand All @@ -110,7 +110,7 @@ func TestMakeDownloadSpec(t *testing.T) {
Platform: "linux",
SSLBuildNeeded: false,
Arch: "x86_64",
OSName: "ubuntu2004",
OSName: "ubuntu1804", // Ubuntu 20.04 is not supported by Mongo 4.0.5, so it falls back to Ubuntu 18.04
},
},
"arm64 ubuntu 20.04 and newer mongo": {
Expand Down Expand Up @@ -531,14 +531,14 @@ func TestMakeDownloadSpec(t *testing.T) {
etcFolder: "ubuntu2004",
goArch: "arm64",

expectedError: "memongo does not support automatic downloading on your system: Mongo doesn't support your environment, ubuntu2004/arm64, on version 4.1.0",
expectedError: "memongo does not support automatic downloading on your system: Mongo doesn't support your environment, ubuntu1804/arm64, on version 4.1.0", // The OS name is wrong because we don't support Ubuntu 20.04 on Mongo 4.1.0 so it falls back to Ubuntu 18.04
},
"MongoDB Unsupported older version for arm64 ubuntu2204": {
mongoVersion: "4.1.0",
etcFolder: "ubuntu2204",
goArch: "arm64",

expectedError: "memongo does not support automatic downloading on your system: Mongo doesn't support your environment, ubuntu2204/arm64, on version 4.1.0",
expectedError: "memongo does not support automatic downloading on your system: Mongo doesn't support your environment, ubuntu1804/arm64, on version 4.1.0", // The OS name is wrong because we don't support Ubuntu 22.04 on Mongo 4.1.0 so it falls back to Ubuntu 18.04
},
"MongoDB Unsupported older version for arm64 amazon2": {
mongoVersion: "4.1.0",
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
Loading