mirror of
https://github.com/minio/minio.git
synced 2026-02-04 18:00:15 -05:00
Improve duration humanization. (#4071)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user