Skip to content

Commit

Permalink
Relax runtime requirement do not fail, print warning (minio#6017)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored and nitisht committed Jun 6, 2018
1 parent 3143454 commit 9d41051
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016,2017 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017, 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,8 +54,7 @@ func checkGoVersion(goVersionStr string) error {
}

if !constraint.Check(goVersion) {
return fmt.Errorf("Minio is not compiled by Go %s. Please recompile accordingly",
goVersionConstraint)
return fmt.Errorf("Minio is not compiled by go %s. Minimum required version is %s, go %s release is known to have security issues. Please recompile accordingly", goVersionConstraint, minGoVersion, runtime.Version()[2:])
}

return nil
Expand All @@ -65,7 +64,7 @@ func main() {
// When `go get` is used minimum Go version check is not triggered but it would have compiled it successfully.
// However such binary will fail at runtime, hence we also check Go version at runtime.
if err := checkGoVersion(runtime.Version()[2:]); err != nil {
console.Fatalln("Go runtime version check failed.", err)
console.Errorln(err)
}

minio.Main(os.Args)
Expand Down
32 changes: 14 additions & 18 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2017 Minio, Inc.
* Minio Cloud Storage, (C) 2017, 2018 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,34 +17,30 @@
package main

import (
"fmt"
"testing"
)

func TestCheckGoVersion(t *testing.T) {
// Test success cases.
testCases := []struct {
version string
expectedErr error
version string
success bool
}{
{minGoVersion, nil},
{"1.6.8", fmt.Errorf("Minio is not compiled by Go >= 1.9.4. Please recompile accordingly")},
{"1.5", fmt.Errorf("Minio is not compiled by Go >= 1.9.4. Please recompile accordingly")},
{"0.1", fmt.Errorf("Minio is not compiled by Go >= 1.9.4. Please recompile accordingly")},
{".1", fmt.Errorf("Malformed version: .1")},
{"somejunk", fmt.Errorf("Malformed version: somejunk")},
{minGoVersion, true},
{"1.6.8", false},
{"1.5", false},
{"0.1", false},
{".1", false},
{"somejunk", false},
}

for _, testCase := range testCases {
err := checkGoVersion(testCase.version)
if testCase.expectedErr == nil {
if err != nil {
t.Fatalf("expected: %v, got: %v", testCase.expectedErr, err)
}
} else if err == nil {
t.Fatalf("expected: %v, got: %v", testCase.expectedErr, err)
} else if testCase.expectedErr.Error() != err.Error() {
t.Fatalf("expected: %v, got: %v", testCase.expectedErr, err)
if err != nil && testCase.success {
t.Fatalf("Test %v, expected: success, got: %v", testCase, err)
}
if err == nil && !testCase.success {
t.Fatalf("Test %v, expected: failure, got: success", testCase)
}
}
}

0 comments on commit 9d41051

Please sign in to comment.