Improve duration humanization. (#4071)

This commit is contained in:
Bala FA
2017-04-26 16:08:35 +05:30
committed by Harshavardhana
parent 64c1c0f37d
commit cf1fc45142
13 changed files with 167 additions and 260 deletions

View File

@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2015 Minio, Inc.
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,18 +17,34 @@
package cmd
import (
"runtime"
"strings"
"testing"
"time"
"github.com/fatih/color"
)
// Tests update notifier string builder.
func TestUpdateNotifier(t *testing.T) {
colorUpdateMsg := colorizeUpdateMessage(minioReleaseURL, time.Duration(72*time.Hour))
if !strings.Contains(colorUpdateMsg, "minutes") {
t.Fatal("Duration string not found in colorized update message", colorUpdateMsg)
plainMsg := "You are running an older version of Minio released "
colorMsg := plainMsg
yellow := color.New(color.FgYellow, color.Bold).SprintfFunc()
if runtime.GOOS == "windows" {
plainMsg += "3 days from now"
colorMsg += yellow("3 days from now")
} else {
plainMsg += "2 days from now"
colorMsg += yellow("2 days from now")
}
if !strings.Contains(colorUpdateMsg, minioReleaseURL) {
updateMsg := colorizeUpdateMessage(minioReleaseURL, time.Duration(72*time.Hour))
if !(strings.Contains(updateMsg, plainMsg) || strings.Contains(updateMsg, colorMsg)) {
t.Fatal("Duration string not found in colorized update message", updateMsg)
}
if !strings.Contains(updateMsg, minioReleaseURL) {
t.Fatal("Update message not found in colorized update message", minioReleaseURL)
}
}