mirror of
https://github.com/minio/minio.git
synced 2025-11-08 21:24:55 -05:00
refactor server update behavior (#10107)
This commit is contained in:
@@ -17,10 +17,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -271,7 +273,12 @@ func TestDownloadReleaseData(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
result, err := downloadReleaseURL(testCase.releaseChecksumURL, 1*time.Second, "")
|
||||
u, err := url.Parse(testCase.releaseChecksumURL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
result, err := downloadReleaseURL(u, 1*time.Second, "")
|
||||
if testCase.expectedErr == nil {
|
||||
if err != nil {
|
||||
t.Fatalf("error: expected: %v, got: %v", testCase.expectedErr, err)
|
||||
@@ -294,31 +301,29 @@ func TestParseReleaseData(t *testing.T) {
|
||||
data string
|
||||
expectedResult time.Time
|
||||
expectedSha256hex string
|
||||
expectedErr error
|
||||
expectedErr bool
|
||||
}{
|
||||
{"more than two fields", time.Time{}, "", fmt.Errorf("Unknown release data `more than two fields`")},
|
||||
{"more than", time.Time{}, "", fmt.Errorf("Unknown release information `than`")},
|
||||
{"more than.two.fields", time.Time{}, "", fmt.Errorf("Unknown release `than.two.fields`")},
|
||||
{"more minio.RELEASE.fields", time.Time{}, "", fmt.Errorf(`Unknown release tag format. parsing time "fields" as "2006-01-02T15-04-05Z": cannot parse "fields" as "2006"`)},
|
||||
{"more minio.RELEASE.2016-10-07T01-16-39Z", releaseTime, "more", nil},
|
||||
{"fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z\n", releaseTime, "fbe246edbd382902db9a4035df7dce8cb441357d", nil},
|
||||
{"fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z.customer-hotfix\n", releaseTime, "fbe246edbd382902db9a4035df7dce8cb441357d", nil},
|
||||
{"more than two fields", time.Time{}, "", true},
|
||||
{"more than", time.Time{}, "", true},
|
||||
{"more than.two.fields", time.Time{}, "", true},
|
||||
{"more minio.RELEASE.fields", time.Time{}, "", true},
|
||||
{"more minio.RELEASE.2016-10-07T01-16-39Z", time.Time{}, "", true},
|
||||
{"fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z\n", releaseTime, "fbe246edbd382902db9a4035df7dce8cb441357d", false},
|
||||
{"fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z.customer-hotfix\n", releaseTime, "fbe246edbd382902db9a4035df7dce8cb441357d", false},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
sha256Hex, result, err := parseReleaseData(testCase.data)
|
||||
if testCase.expectedErr == nil {
|
||||
sha256Sum, result, err := parseReleaseData(testCase.data)
|
||||
if !testCase.expectedErr {
|
||||
if err != nil {
|
||||
t.Errorf("error case %d: expected: %v, got: %v", i+1, testCase.expectedErr, err)
|
||||
t.Errorf("error case %d: expected no error, got: %v", i+1, err)
|
||||
}
|
||||
} else if err == nil {
|
||||
t.Errorf("error case %d: expected: %v, got: %v", i+1, testCase.expectedErr, err)
|
||||
} else if testCase.expectedErr.Error() != err.Error() {
|
||||
t.Errorf("error case %d: expected: %v, got: %v", i+1, testCase.expectedErr, err)
|
||||
t.Errorf("error case %d: expected error got: %v", i+1, err)
|
||||
}
|
||||
if err == nil {
|
||||
if sha256Hex != testCase.expectedSha256hex {
|
||||
t.Errorf("case %d: result: expected: %v, got: %v", i+1, testCase.expectedSha256hex, sha256Hex)
|
||||
if hex.EncodeToString(sha256Sum) != testCase.expectedSha256hex {
|
||||
t.Errorf("case %d: result: expected: %v, got: %x", i+1, testCase.expectedSha256hex, sha256Sum)
|
||||
}
|
||||
if !testCase.expectedResult.Equal(result) {
|
||||
t.Errorf("case %d: result: expected: %v, got: %v", i+1, testCase.expectedResult, result)
|
||||
|
||||
Reference in New Issue
Block a user