Relax runtime requirement do not fail, print warning (#6017)

master
Harshavardhana 7 years ago committed by Nitish Tiwari
parent 3143454982
commit 9d41051e91
  1. 7
      main.go
  2. 32
      main_test.go

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -54,8 +54,7 @@ func checkGoVersion(goVersionStr string) error {
} }
if !constraint.Check(goVersion) { if !constraint.Check(goVersion) {
return fmt.Errorf("Minio is not compiled by Go %s. Please recompile accordingly", 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:])
goVersionConstraint)
} }
return nil return nil
@ -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. // 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. // However such binary will fail at runtime, hence we also check Go version at runtime.
if err := checkGoVersion(runtime.Version()[2:]); err != nil { if err := checkGoVersion(runtime.Version()[2:]); err != nil {
console.Fatalln("Go runtime version check failed.", err) console.Errorln(err)
} }
minio.Main(os.Args) minio.Main(os.Args)

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,34 +17,30 @@
package main package main
import ( import (
"fmt"
"testing" "testing"
) )
func TestCheckGoVersion(t *testing.T) { func TestCheckGoVersion(t *testing.T) {
// Test success cases. // Test success cases.
testCases := []struct { testCases := []struct {
version string version string
expectedErr error success bool
}{ }{
{minGoVersion, nil}, {minGoVersion, true},
{"1.6.8", fmt.Errorf("Minio is not compiled by Go >= 1.9.4. Please recompile accordingly")}, {"1.6.8", false},
{"1.5", fmt.Errorf("Minio is not compiled by Go >= 1.9.4. Please recompile accordingly")}, {"1.5", false},
{"0.1", fmt.Errorf("Minio is not compiled by Go >= 1.9.4. Please recompile accordingly")}, {"0.1", false},
{".1", fmt.Errorf("Malformed version: .1")}, {".1", false},
{"somejunk", fmt.Errorf("Malformed version: somejunk")}, {"somejunk", false},
} }
for _, testCase := range testCases { for _, testCase := range testCases {
err := checkGoVersion(testCase.version) err := checkGoVersion(testCase.version)
if testCase.expectedErr == nil { if err != nil && testCase.success {
if err != nil { t.Fatalf("Test %v, expected: success, got: %v", testCase, err)
t.Fatalf("expected: %v, got: %v", testCase.expectedErr, err) }
} if err == nil && !testCase.success {
} else if err == nil { t.Fatalf("Test %v, expected: failure, got: success", testCase)
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)
} }
} }
} }

Loading…
Cancel
Save