mirror of
https://github.com/minio/mc.git
synced 2025-11-12 01:02:26 +03:00
Migrate to golang1.5 with new GO15VENDOREXPERIMENT enabled
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.4.2
|
- 1.5
|
||||||
sudo: false
|
sudo: false
|
||||||
notifications:
|
notifications:
|
||||||
slack:
|
slack:
|
||||||
|
|||||||
10
INSTALLGO.md
10
INSTALLGO.md
@@ -7,15 +7,15 @@ This installation guide is based on Ubuntu 14.04+ on x86-64 platform.
|
|||||||
$ sudo apt-get install git build-essential
|
$ sudo apt-get install git build-essential
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Install Go 1.4+
|
##### Install Go 1.5+
|
||||||
|
|
||||||
Download Go 1.4+ from [https://golang.org/dl/](https://golang.org/dl/).
|
Download Go 1.5+ from [https://golang.org/dl/](https://golang.org/dl/).
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ wget https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz
|
$ wget https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
|
||||||
$ mkdir -p ${HOME}/bin/
|
$ mkdir -p ${HOME}/bin/
|
||||||
$ mkdir -p ${HOME}/go/
|
$ mkdir -p ${HOME}/go/
|
||||||
$ tar -C ${HOME}/bin/ -xzf go1.4.linux-amd64.tar.gz
|
$ tar -C ${HOME}/bin/ -xzf go1.5.linux-amd64.tar.gz
|
||||||
```
|
```
|
||||||
##### Setup GOROOT and GOPATH
|
##### Setup GOROOT and GOPATH
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/maste
|
|||||||
$ brew install git python
|
$ brew install git python
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Install Go 1.4+
|
##### Install Go 1.5+
|
||||||
|
|
||||||
Install golang binaries using `brew`
|
Install golang binaries using `brew`
|
||||||
|
|
||||||
|
|||||||
28
Makefile
28
Makefile
@@ -1,5 +1,5 @@
|
|||||||
## filter multiple GOPATH
|
## filter multiple GOPATH
|
||||||
all: getdeps install
|
all: install
|
||||||
|
|
||||||
checkdeps:
|
checkdeps:
|
||||||
@echo "Checking deps:"
|
@echo "Checking deps:"
|
||||||
@@ -20,37 +20,37 @@ verifiers: getdeps vet fmt lint cyclo deadcode
|
|||||||
|
|
||||||
vet:
|
vet:
|
||||||
@echo "Running $@:"
|
@echo "Running $@:"
|
||||||
@go vet .
|
@GO15VENDOREXPERIMENT=1 go vet .
|
||||||
@go vet github.com/minio/mc/pkg...
|
@GO15VENDOREXPERIMENT=1 go vet github.com/minio/mc/pkg...
|
||||||
fmt:
|
fmt:
|
||||||
@echo "Running $@:"
|
@echo "Running $@:"
|
||||||
@gofmt -s -l *.go
|
@GO15VENDOREXPERIMENT=1 gofmt -s -l *.go
|
||||||
@gofmt -s -l pkg
|
@GO15VENDOREXPERIMENT=1 gofmt -s -l pkg
|
||||||
lint:
|
lint:
|
||||||
@echo "Running $@:"
|
@echo "Running $@:"
|
||||||
@golint .
|
@GO15VENDOREXPERIMENT=1 golint .
|
||||||
@golint pkg
|
@GO15VENDOREXPERIMENT=1 golint pkg
|
||||||
|
|
||||||
cyclo:
|
cyclo:
|
||||||
@echo "Running $@:"
|
@echo "Running $@:"
|
||||||
@gocyclo -over 30 .
|
@GO15VENDOREXPERIMENT=1 gocyclo -over 30 .
|
||||||
|
|
||||||
deadcode:
|
deadcode:
|
||||||
@echo "Running $@:"
|
@echo "Running $@:"
|
||||||
@deadcode
|
@GO15VENDOREXPERIMENT=1 deadcode
|
||||||
|
|
||||||
build: getdeps verifiers
|
build: getdeps verifiers
|
||||||
@echo "Installing mc:"
|
@echo "Installing mc:"
|
||||||
@go test -race ./
|
@GO15VENDOREXPERIMENT=1 go test -race ./
|
||||||
@go test -race github.com/minio/mc/pkg...
|
@GO15VENDOREXPERIMENT=1 go test -race github.com/minio/mc/pkg...
|
||||||
|
|
||||||
gomake-all: build
|
gomake-all: build
|
||||||
@go install github.com/minio/mc
|
@GO15VENDOREXPERIMENT=1 go install github.com/minio/mc
|
||||||
@mkdir -p $(HOME)/.mc
|
@mkdir -p $(HOME)/.mc
|
||||||
|
|
||||||
release: genversion
|
release: genversion
|
||||||
@echo "Installing mc with new version.go:"
|
@echo "Installing mc with new version.go:"
|
||||||
@go install github.com/minio/mc
|
@GO15VENDOREXPERIMENT=1 go install github.com/minio/mc
|
||||||
@mkdir -p $(HOME)/.mc
|
@mkdir -p $(HOME)/.mc
|
||||||
|
|
||||||
genversion:
|
genversion:
|
||||||
@@ -58,7 +58,7 @@ genversion:
|
|||||||
@go run genversion.go
|
@go run genversion.go
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
@go test -race -coverprofile=cover.out
|
@GO15VENDOREXPERIMENT=1 go test -race -coverprofile=cover.out
|
||||||
@go tool cover -html=cover.out && echo "Visit your browser"
|
@go tool cover -html=cover.out && echo "Visit your browser"
|
||||||
|
|
||||||
install: gomake-all
|
install: gomake-all
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// validAliasURL: use net/url.Parse to validate
|
// validAliasURL: use net/url.Parse to validate
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ _init() {
|
|||||||
CLANG_VERSION="3.5"
|
CLANG_VERSION="3.5"
|
||||||
YASM_VERSION="1.2.0"
|
YASM_VERSION="1.2.0"
|
||||||
GIT_VERSION="1.0"
|
GIT_VERSION="1.0"
|
||||||
GO_VERSION="1.4"
|
GO_VERSION="1.5"
|
||||||
OSX_VERSION="10.8"
|
OSX_VERSION="10.8"
|
||||||
UNAME=$(uname -sm)
|
UNAME=$(uname -sm)
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestCatCmd(c *C) {
|
func (s *CmdTestSuite) TestCatCmd(c *C) {
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ import (
|
|||||||
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/quick"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var customConfigDir string
|
var customConfigDir string
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
"github.com/minio/mc/pkg/client/fs"
|
"github.com/minio/mc/pkg/client/fs"
|
||||||
"github.com/minio/mc/pkg/client/s3"
|
"github.com/minio/mc/pkg/client/s3"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check if the target URL represents folder. It may or may not exist yet.
|
// Check if the target URL represents folder. It may or may not exist yet.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestCommonMethods(c *C) {
|
func (s *CmdTestSuite) TestCommonMethods(c *C) {
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/quick"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configure minio client
|
// Configure minio client
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/quick"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configV2 struct {
|
type configV2 struct {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestConfigContext(c *C) {
|
func (s *CmdTestSuite) TestConfigContext(c *C) {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyMessage container for file copy messages
|
// CopyMessage container for file copy messages
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type copyURLs struct {
|
type copyURLs struct {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestCopyURLType(c *C) {
|
func (s *CmdTestSuite) TestCopyURLType(c *C) {
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
4
diff.go
4
diff.go
@@ -24,10 +24,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/internal/github.com/tchap/go-patricia/patricia"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
"github.com/tchap/go-patricia/patricia"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestDiffObjects(c *C) {
|
func (s *CmdTestSuite) TestDiffObjects(c *C) {
|
||||||
|
|||||||
2
error.go
2
error.go
@@ -21,8 +21,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
|
// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
|
||||||
|
|||||||
2
flags.go
2
flags.go
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/minio/mc/internal/github.com/minio/cli"
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
// Collection of mc commands currently supported are
|
// Collection of mc commands currently supported are
|
||||||
var commands = []cli.Command{}
|
var commands = []cli.Command{}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type hostConfig struct {
|
type hostConfig struct {
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
4
ls.go
4
ls.go
@@ -22,10 +22,10 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
/// ls - related internal functions
|
/// ls - related internal functions
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestLSCmd(c *C) {
|
func (s *CmdTestSuite) TestLSCmd(c *C) {
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -25,9 +25,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/pb"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/pb"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Check for the environment early on and gracefully report.
|
// Check for the environment early on and gracefully report.
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestMbAndAccessCmd(c *C) {
|
func (s *CmdTestSuite) TestMbAndAccessCmd(c *C) {
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/internal/github.com/tchap/go-patricia/patricia"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
"github.com/tchap/go-patricia/patricia"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mirrorURLs struct {
|
type mirrorURLs struct {
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/mc/internal/github.com/olekukonko/ts"
|
"github.com/olekukonko/ts"
|
||||||
)
|
)
|
||||||
|
|
||||||
// printUpdateNotify - inspired from Yeoman project npm package https://github.com/yeoman/update-notifier
|
// printUpdateNotify - inspired from Yeoman project npm package https://github.com/yeoman/update-notifier
|
||||||
|
|||||||
8
pb.go
8
pb.go
@@ -24,10 +24,10 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
"github.com/minio/mc/internal/github.com/minio/pb"
|
"github.com/minio/pb"
|
||||||
"github.com/minio/mc/internal/github.com/olekukonko/ts"
|
"github.com/olekukonko/ts"
|
||||||
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client - client interface
|
// Client - client interface
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import (
|
|||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fsClient struct {
|
type fsClient struct {
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
"github.com/minio/mc/pkg/client/fs"
|
"github.com/minio/mc/pkg/client/fs"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio-go"
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio-go"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config - see http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
|
// Config - see http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type bucketHandler struct {
|
type bucketHandler struct {
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ import (
|
|||||||
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/mc/internal/github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
"github.com/minio/mc/internal/github.com/shiena/ansicolor"
|
"github.com/shiena/ansicolor"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NoDebugPrint defines if the input should be printed in debug or not. By default it's set to true.
|
// NoDebugPrint defines if the input should be printed in debug or not. By default it's set to true.
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ package console
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/quick"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sessionV1 struct {
|
type sessionV1 struct {
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/quick"
|
||||||
)
|
)
|
||||||
|
|
||||||
// migrateSessionV1ToV2 migrates all session files from v1 to v2.
|
// migrateSessionV1ToV2 migrates all session files from v1 to v2.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func migrateSession() {
|
func migrateSession() {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
. "github.com/minio/mc/internal/gopkg.in/check.v1"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *CmdTestSuite) TestValidSessionID(c *C) {
|
func (s *CmdTestSuite) TestValidSessionID(c *C) {
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help message.
|
// Help message.
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
"github.com/minio/mc/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Updates container to hold updates json
|
// Updates container to hold updates json
|
||||||
|
|||||||
2
url.go
2
url.go
@@ -19,8 +19,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
|
|
||||||
"github.com/minio/mc/pkg/client"
|
"github.com/minio/mc/pkg/client"
|
||||||
|
"github.com/minio/minio/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ``...`` recursiveSeparator
|
// ``...`` recursiveSeparator
|
||||||
|
|||||||
@@ -1,95 +1,95 @@
|
|||||||
{
|
{
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"ignore": "test",
|
"ignore": "",
|
||||||
"package": [
|
"package": [
|
||||||
{
|
{
|
||||||
"canonical": "github.com/dustin/go-humanize",
|
"canonical": "github.com/dustin/go-humanize",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/dustin/go-humanize",
|
"local": "vendor/github.com/dustin/go-humanize",
|
||||||
"revision": "5721d85c9a0e65ee65005e7da48c56612ae04ee3",
|
"revision": "1c212aae1d02984808182b98b0da7a3e07e4c770",
|
||||||
"revisionTime": "2015-08-20T22:35:37-07:00"
|
"revisionTime": "2015-08-09T13:14:05-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/fatih/color",
|
"canonical": "github.com/fatih/color",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/fatih/color",
|
"local": "vendor/github.com/fatih/color",
|
||||||
"revision": "f773d4c806cc8e4a5749d6a35e2a4bbcd71443d6",
|
"revision": "f773d4c806cc8e4a5749d6a35e2a4bbcd71443d6",
|
||||||
"revisionTime": "2015-08-04T08:17:43+03:00"
|
"revisionTime": "2015-08-04T08:17:43+03:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/fatih/structs",
|
"canonical": "github.com/fatih/structs",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/fatih/structs",
|
"local": "vendor/github.com/fatih/structs",
|
||||||
"revision": "5721d85c9a0e65ee65005e7da48c56612ae04ee3",
|
"revision": "5721d85c9a0e65ee65005e7da48c56612ae04ee3",
|
||||||
"revisionTime": "2015-08-20T22:35:37-07:00"
|
"revisionTime": "2015-08-20T22:35:37-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/mattn/go-isatty",
|
"canonical": "github.com/mattn/go-isatty",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/mattn/go-isatty",
|
"local": "vendor/github.com/mattn/go-isatty",
|
||||||
"revision": "7fcbc72f853b92b5720db4a6b8482be612daef24",
|
"revision": "7fcbc72f853b92b5720db4a6b8482be612daef24",
|
||||||
"revisionTime": "2015-08-14T09:26:29+09:00"
|
"revisionTime": "2015-08-14T09:26:29+09:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/minio/cli",
|
"canonical": "github.com/minio/cli",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/minio/cli",
|
"local": "vendor/github.com/minio/cli",
|
||||||
"revision": "ee386baecc113eef2b8945df429120a5aec319ef",
|
"revision": "ee386baecc113eef2b8945df429120a5aec319ef",
|
||||||
"revisionTime": "2015-08-19T11:23:55-07:00"
|
"revisionTime": "2015-08-19T11:23:55-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/minio/minio-go",
|
"canonical": "github.com/minio/minio-go",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/minio/minio-go",
|
"local": "vendor/github.com/minio/minio-go",
|
||||||
"revision": "d3dc9fd261cacbe64e4c0e5f3929e1fb846db42b",
|
"revision": "ca58a5b7e02c2e0adf5fb404df3545f0ddc45b29",
|
||||||
"revisionTime": "2015-08-21T20:20:57-07:00"
|
"revisionTime": "2015-08-22T15:40:20-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/minio/minio/pkg/probe",
|
"canonical": "github.com/minio/minio/pkg/probe",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/minio/minio/pkg/probe",
|
"local": "vendor/github.com/minio/minio/pkg/probe",
|
||||||
"revision": "5721d85c9a0e65ee65005e7da48c56612ae04ee3",
|
"revision": "4d1f38d28cabcfa321e9d88acef67e16e7bafb2a",
|
||||||
"revisionTime": "2015-08-20T22:35:37-07:00"
|
"revisionTime": "2015-08-22T18:37:56-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/minio/minio/pkg/quick",
|
"canonical": "github.com/minio/minio/pkg/quick",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/minio/minio/pkg/quick",
|
"local": "vendor/github.com/minio/minio/pkg/quick",
|
||||||
"revision": "5721d85c9a0e65ee65005e7da48c56612ae04ee3",
|
"revision": "4d1f38d28cabcfa321e9d88acef67e16e7bafb2a",
|
||||||
"revisionTime": "2015-08-20T22:35:37-07:00"
|
"revisionTime": "2015-08-22T18:37:56-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/minio/pb",
|
"canonical": "github.com/minio/pb",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/minio/pb",
|
"local": "vendor/github.com/minio/pb",
|
||||||
"revision": "6a97c3b0da073f974e0b8d1ac1bc42c0a7adca46",
|
"revision": "6a97c3b0da073f974e0b8d1ac1bc42c0a7adca46",
|
||||||
"revisionTime": "2015-08-12T18:13:54-07:00"
|
"revisionTime": "2015-08-12T18:13:54-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/olekukonko/ts",
|
"canonical": "github.com/olekukonko/ts",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/olekukonko/ts",
|
"local": "vendor/github.com/olekukonko/ts",
|
||||||
"revision": "ecf753e7c962639ab5a1fb46f7da627d4c0a04b8",
|
"revision": "ecf753e7c962639ab5a1fb46f7da627d4c0a04b8",
|
||||||
"revisionTime": "2014-04-12T15:01:45-07:00"
|
"revisionTime": "2014-04-12T15:01:45-07:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/shiena/ansicolor",
|
"canonical": "github.com/shiena/ansicolor",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/shiena/ansicolor",
|
"local": "vendor/github.com/shiena/ansicolor",
|
||||||
"revision": "a5e2b567a4dd6cc74545b8a4f27c9d63b9e7735b",
|
"revision": "a5e2b567a4dd6cc74545b8a4f27c9d63b9e7735b",
|
||||||
"revisionTime": "2015-07-19T16:15:31+09:00"
|
"revisionTime": "2015-07-19T16:15:31+09:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "github.com/tchap/go-patricia/patricia",
|
"canonical": "github.com/tchap/go-patricia/patricia",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "github.com/tchap/go-patricia/patricia",
|
"local": "vendor/github.com/tchap/go-patricia/patricia",
|
||||||
"revision": "a560f85131e8aafc2cc4bcb1e265ae3fc6ee5f50",
|
"revision": "a560f85131e8aafc2cc4bcb1e265ae3fc6ee5f50",
|
||||||
"revisionTime": "2015-06-11T09:53:39+02:00"
|
"revisionTime": "2015-06-11T09:53:39+02:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"canonical": "gopkg.in/check.v1",
|
"canonical": "gopkg.in/check.v1",
|
||||||
"comment": "",
|
"comment": "",
|
||||||
"local": "gopkg.in/check.v1",
|
"local": "vendor/gopkg.in/check.v1",
|
||||||
"revision": "11d3bc7aa68e238947792f30573146a3231fc0f1",
|
"revision": "11d3bc7aa68e238947792f30573146a3231fc0f1",
|
||||||
"revisionTime": "2015-07-29T10:04:31+02:00"
|
"revisionTime": "2015-07-29T10:04:31+02:00"
|
||||||
}
|
}
|
||||||
219
vendor/github.com/dustin/go-humanize/bigbytes_test.go
generated
vendored
Normal file
219
vendor/github.com/dustin/go-humanize/bigbytes_test.go
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBigByteParsing(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
in string
|
||||||
|
exp uint64
|
||||||
|
}{
|
||||||
|
{"42", 42},
|
||||||
|
{"42MB", 42000000},
|
||||||
|
{"42MiB", 44040192},
|
||||||
|
{"42mb", 42000000},
|
||||||
|
{"42mib", 44040192},
|
||||||
|
{"42MIB", 44040192},
|
||||||
|
{"42 MB", 42000000},
|
||||||
|
{"42 MiB", 44040192},
|
||||||
|
{"42 mb", 42000000},
|
||||||
|
{"42 mib", 44040192},
|
||||||
|
{"42 MIB", 44040192},
|
||||||
|
{"42.5MB", 42500000},
|
||||||
|
{"42.5MiB", 44564480},
|
||||||
|
{"42.5 MB", 42500000},
|
||||||
|
{"42.5 MiB", 44564480},
|
||||||
|
// No need to say B
|
||||||
|
{"42M", 42000000},
|
||||||
|
{"42Mi", 44040192},
|
||||||
|
{"42m", 42000000},
|
||||||
|
{"42mi", 44040192},
|
||||||
|
{"42MI", 44040192},
|
||||||
|
{"42 M", 42000000},
|
||||||
|
{"42 Mi", 44040192},
|
||||||
|
{"42 m", 42000000},
|
||||||
|
{"42 mi", 44040192},
|
||||||
|
{"42 MI", 44040192},
|
||||||
|
{"42.5M", 42500000},
|
||||||
|
{"42.5Mi", 44564480},
|
||||||
|
{"42.5 M", 42500000},
|
||||||
|
{"42.5 Mi", 44564480},
|
||||||
|
// Large testing, breaks when too much larger than
|
||||||
|
// this.
|
||||||
|
{"12.5 EB", uint64(12.5 * float64(EByte))},
|
||||||
|
{"12.5 E", uint64(12.5 * float64(EByte))},
|
||||||
|
{"12.5 EiB", uint64(12.5 * float64(EiByte))},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range tests {
|
||||||
|
got, err := ParseBigBytes(p.in)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Couldn't parse %v: %v", p.in, err)
|
||||||
|
} else {
|
||||||
|
if got.Uint64() != p.exp {
|
||||||
|
t.Errorf("Expected %v for %v, got %v",
|
||||||
|
p.exp, p.in, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBigByteErrors(t *testing.T) {
|
||||||
|
got, err := ParseBigBytes("84 JB")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error, got %v", got)
|
||||||
|
}
|
||||||
|
got, err = ParseBigBytes("")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error parsing nothing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func bbyte(in uint64) string {
|
||||||
|
return BigBytes((&big.Int{}).SetUint64(in))
|
||||||
|
}
|
||||||
|
|
||||||
|
func bibyte(in uint64) string {
|
||||||
|
return BigIBytes((&big.Int{}).SetUint64(in))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBigBytes(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"bytes(0)", bbyte(0), "0B"},
|
||||||
|
{"bytes(1)", bbyte(1), "1B"},
|
||||||
|
{"bytes(803)", bbyte(803), "803B"},
|
||||||
|
{"bytes(999)", bbyte(999), "999B"},
|
||||||
|
|
||||||
|
{"bytes(1024)", bbyte(1024), "1.0kB"},
|
||||||
|
{"bytes(1MB - 1)", bbyte(MByte - Byte), "1000kB"},
|
||||||
|
|
||||||
|
{"bytes(1MB)", bbyte(1024 * 1024), "1.0MB"},
|
||||||
|
{"bytes(1GB - 1K)", bbyte(GByte - KByte), "1000MB"},
|
||||||
|
|
||||||
|
{"bytes(1GB)", bbyte(GByte), "1.0GB"},
|
||||||
|
{"bytes(1TB - 1M)", bbyte(TByte - MByte), "1000GB"},
|
||||||
|
|
||||||
|
{"bytes(1TB)", bbyte(TByte), "1.0TB"},
|
||||||
|
{"bytes(1PB - 1T)", bbyte(PByte - TByte), "999TB"},
|
||||||
|
|
||||||
|
{"bytes(1PB)", bbyte(PByte), "1.0PB"},
|
||||||
|
{"bytes(1PB - 1T)", bbyte(EByte - PByte), "999PB"},
|
||||||
|
|
||||||
|
{"bytes(1EB)", bbyte(EByte), "1.0EB"},
|
||||||
|
// Overflows.
|
||||||
|
// {"bytes(1EB - 1P)", Bytes((KByte*EByte)-PByte), "1023EB"},
|
||||||
|
|
||||||
|
{"bytes(0)", bibyte(0), "0B"},
|
||||||
|
{"bytes(1)", bibyte(1), "1B"},
|
||||||
|
{"bytes(803)", bibyte(803), "803B"},
|
||||||
|
{"bytes(1023)", bibyte(1023), "1023B"},
|
||||||
|
|
||||||
|
{"bytes(1024)", bibyte(1024), "1.0KiB"},
|
||||||
|
{"bytes(1MB - 1)", bibyte(MiByte - IByte), "1024KiB"},
|
||||||
|
|
||||||
|
{"bytes(1MB)", bibyte(1024 * 1024), "1.0MiB"},
|
||||||
|
{"bytes(1GB - 1K)", bibyte(GiByte - KiByte), "1024MiB"},
|
||||||
|
|
||||||
|
{"bytes(1GB)", bibyte(GiByte), "1.0GiB"},
|
||||||
|
{"bytes(1TB - 1M)", bibyte(TiByte - MiByte), "1024GiB"},
|
||||||
|
|
||||||
|
{"bytes(1TB)", bibyte(TiByte), "1.0TiB"},
|
||||||
|
{"bytes(1PB - 1T)", bibyte(PiByte - TiByte), "1023TiB"},
|
||||||
|
|
||||||
|
{"bytes(1PB)", bibyte(PiByte), "1.0PiB"},
|
||||||
|
{"bytes(1PB - 1T)", bibyte(EiByte - PiByte), "1023PiB"},
|
||||||
|
|
||||||
|
{"bytes(1EiB)", bibyte(EiByte), "1.0EiB"},
|
||||||
|
// Overflows.
|
||||||
|
// {"bytes(1EB - 1P)", bibyte((KIByte*EIByte)-PiByte), "1023EB"},
|
||||||
|
|
||||||
|
{"bytes(5.5GiB)", bibyte(5.5 * GiByte), "5.5GiB"},
|
||||||
|
|
||||||
|
{"bytes(5.5GB)", bbyte(5.5 * GByte), "5.5GB"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVeryBigBytes(t *testing.T) {
|
||||||
|
b, _ := (&big.Int{}).SetString("15347691069326346944512", 10)
|
||||||
|
s := BigBytes(b)
|
||||||
|
if s != "15ZB" {
|
||||||
|
t.Errorf("Expected 15ZB, got %v", s)
|
||||||
|
}
|
||||||
|
s = BigIBytes(b)
|
||||||
|
if s != "13ZiB" {
|
||||||
|
t.Errorf("Expected 13ZiB, got %v", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ = (&big.Int{}).SetString("15716035654990179271180288", 10)
|
||||||
|
s = BigBytes(b)
|
||||||
|
if s != "16YB" {
|
||||||
|
t.Errorf("Expected 16YB, got %v", s)
|
||||||
|
}
|
||||||
|
s = BigIBytes(b)
|
||||||
|
if s != "13YiB" {
|
||||||
|
t.Errorf("Expected 13YiB, got %v", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVeryVeryBigBytes(t *testing.T) {
|
||||||
|
b, _ := (&big.Int{}).SetString("16093220510709943573688614912", 10)
|
||||||
|
s := BigBytes(b)
|
||||||
|
if s != "16093YB" {
|
||||||
|
t.Errorf("Expected 16093YB, got %v", s)
|
||||||
|
}
|
||||||
|
s = BigIBytes(b)
|
||||||
|
if s != "13312YiB" {
|
||||||
|
t.Errorf("Expected 13312YiB, got %v", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseVeryBig(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
in string
|
||||||
|
out string
|
||||||
|
}{
|
||||||
|
{"16ZB", "16000000000000000000000"},
|
||||||
|
{"16ZiB", "18889465931478580854784"},
|
||||||
|
{"16.5ZB", "16500000000000000000000"},
|
||||||
|
{"16.5ZiB", "19479761741837286506496"},
|
||||||
|
{"16Z", "16000000000000000000000"},
|
||||||
|
{"16Zi", "18889465931478580854784"},
|
||||||
|
{"16.5Z", "16500000000000000000000"},
|
||||||
|
{"16.5Zi", "19479761741837286506496"},
|
||||||
|
|
||||||
|
{"16YB", "16000000000000000000000000"},
|
||||||
|
{"16YiB", "19342813113834066795298816"},
|
||||||
|
{"16.5YB", "16500000000000000000000000"},
|
||||||
|
{"16.5YiB", "19947276023641381382651904"},
|
||||||
|
{"16Y", "16000000000000000000000000"},
|
||||||
|
{"16Yi", "19342813113834066795298816"},
|
||||||
|
{"16.5Y", "16500000000000000000000000"},
|
||||||
|
{"16.5Yi", "19947276023641381382651904"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
x, err := ParseBigBytes(test.in)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error parsing %q: %v", test.in, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if x.String() != test.out {
|
||||||
|
t.Errorf("Expected %q for %q, got %v", test.out, test.in, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkParseBigBytes(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ParseBigBytes("16.5Z")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkBigBytes(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
bibyte(16.5 * GByte)
|
||||||
|
}
|
||||||
|
}
|
||||||
144
vendor/github.com/dustin/go-humanize/bytes_test.go
generated
vendored
Normal file
144
vendor/github.com/dustin/go-humanize/bytes_test.go
generated
vendored
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestByteParsing(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
in string
|
||||||
|
exp uint64
|
||||||
|
}{
|
||||||
|
{"42", 42},
|
||||||
|
{"42MB", 42000000},
|
||||||
|
{"42MiB", 44040192},
|
||||||
|
{"42mb", 42000000},
|
||||||
|
{"42mib", 44040192},
|
||||||
|
{"42MIB", 44040192},
|
||||||
|
{"42 MB", 42000000},
|
||||||
|
{"42 MiB", 44040192},
|
||||||
|
{"42 mb", 42000000},
|
||||||
|
{"42 mib", 44040192},
|
||||||
|
{"42 MIB", 44040192},
|
||||||
|
{"42.5MB", 42500000},
|
||||||
|
{"42.5MiB", 44564480},
|
||||||
|
{"42.5 MB", 42500000},
|
||||||
|
{"42.5 MiB", 44564480},
|
||||||
|
// No need to say B
|
||||||
|
{"42M", 42000000},
|
||||||
|
{"42Mi", 44040192},
|
||||||
|
{"42m", 42000000},
|
||||||
|
{"42mi", 44040192},
|
||||||
|
{"42MI", 44040192},
|
||||||
|
{"42 M", 42000000},
|
||||||
|
{"42 Mi", 44040192},
|
||||||
|
{"42 m", 42000000},
|
||||||
|
{"42 mi", 44040192},
|
||||||
|
{"42 MI", 44040192},
|
||||||
|
{"42.5M", 42500000},
|
||||||
|
{"42.5Mi", 44564480},
|
||||||
|
{"42.5 M", 42500000},
|
||||||
|
{"42.5 Mi", 44564480},
|
||||||
|
// Large testing, breaks when too much larger than
|
||||||
|
// this.
|
||||||
|
{"12.5 EB", uint64(12.5 * float64(EByte))},
|
||||||
|
{"12.5 E", uint64(12.5 * float64(EByte))},
|
||||||
|
{"12.5 EiB", uint64(12.5 * float64(EiByte))},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range tests {
|
||||||
|
got, err := ParseBytes(p.in)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Couldn't parse %v: %v", p.in, err)
|
||||||
|
}
|
||||||
|
if got != p.exp {
|
||||||
|
t.Errorf("Expected %v for %v, got %v",
|
||||||
|
p.exp, p.in, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestByteErrors(t *testing.T) {
|
||||||
|
got, err := ParseBytes("84 JB")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error, got %v", got)
|
||||||
|
}
|
||||||
|
got, err = ParseBytes("")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error parsing nothing")
|
||||||
|
}
|
||||||
|
got, err = ParseBytes("16 EiB")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error, got %v", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBytes(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"bytes(0)", Bytes(0), "0B"},
|
||||||
|
{"bytes(1)", Bytes(1), "1B"},
|
||||||
|
{"bytes(803)", Bytes(803), "803B"},
|
||||||
|
{"bytes(999)", Bytes(999), "999B"},
|
||||||
|
|
||||||
|
{"bytes(1024)", Bytes(1024), "1.0kB"},
|
||||||
|
{"bytes(9999)", Bytes(9999), "10kB"},
|
||||||
|
{"bytes(1MB - 1)", Bytes(MByte - Byte), "1000kB"},
|
||||||
|
|
||||||
|
{"bytes(1MB)", Bytes(1024 * 1024), "1.0MB"},
|
||||||
|
{"bytes(1GB - 1K)", Bytes(GByte - KByte), "1000MB"},
|
||||||
|
|
||||||
|
{"bytes(1GB)", Bytes(GByte), "1.0GB"},
|
||||||
|
{"bytes(1TB - 1M)", Bytes(TByte - MByte), "1000GB"},
|
||||||
|
{"bytes(10MB)", Bytes(9999 * 1000), "10MB"},
|
||||||
|
|
||||||
|
{"bytes(1TB)", Bytes(TByte), "1.0TB"},
|
||||||
|
{"bytes(1PB - 1T)", Bytes(PByte - TByte), "999TB"},
|
||||||
|
|
||||||
|
{"bytes(1PB)", Bytes(PByte), "1.0PB"},
|
||||||
|
{"bytes(1PB - 1T)", Bytes(EByte - PByte), "999PB"},
|
||||||
|
|
||||||
|
{"bytes(1EB)", Bytes(EByte), "1.0EB"},
|
||||||
|
// Overflows.
|
||||||
|
// {"bytes(1EB - 1P)", Bytes((KByte*EByte)-PByte), "1023EB"},
|
||||||
|
|
||||||
|
{"bytes(0)", IBytes(0), "0B"},
|
||||||
|
{"bytes(1)", IBytes(1), "1B"},
|
||||||
|
{"bytes(803)", IBytes(803), "803B"},
|
||||||
|
{"bytes(1023)", IBytes(1023), "1023B"},
|
||||||
|
|
||||||
|
{"bytes(1024)", IBytes(1024), "1.0KiB"},
|
||||||
|
{"bytes(1MB - 1)", IBytes(MiByte - IByte), "1024KiB"},
|
||||||
|
|
||||||
|
{"bytes(1MB)", IBytes(1024 * 1024), "1.0MiB"},
|
||||||
|
{"bytes(1GB - 1K)", IBytes(GiByte - KiByte), "1024MiB"},
|
||||||
|
|
||||||
|
{"bytes(1GB)", IBytes(GiByte), "1.0GiB"},
|
||||||
|
{"bytes(1TB - 1M)", IBytes(TiByte - MiByte), "1024GiB"},
|
||||||
|
|
||||||
|
{"bytes(1TB)", IBytes(TiByte), "1.0TiB"},
|
||||||
|
{"bytes(1PB - 1T)", IBytes(PiByte - TiByte), "1023TiB"},
|
||||||
|
|
||||||
|
{"bytes(1PB)", IBytes(PiByte), "1.0PiB"},
|
||||||
|
{"bytes(1PB - 1T)", IBytes(EiByte - PiByte), "1023PiB"},
|
||||||
|
|
||||||
|
{"bytes(1EiB)", IBytes(EiByte), "1.0EiB"},
|
||||||
|
// Overflows.
|
||||||
|
// {"bytes(1EB - 1P)", IBytes((KIByte*EIByte)-PiByte), "1023EB"},
|
||||||
|
|
||||||
|
{"bytes(5.5GiB)", IBytes(5.5 * GiByte), "5.5GiB"},
|
||||||
|
|
||||||
|
{"bytes(5.5GB)", Bytes(5.5 * GByte), "5.5GB"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkParseBytes(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ParseBytes("16.5GB")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkBytes(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Bytes(16.5 * GByte)
|
||||||
|
}
|
||||||
|
}
|
||||||
134
vendor/github.com/dustin/go-humanize/comma_test.go
generated
vendored
Normal file
134
vendor/github.com/dustin/go-humanize/comma_test.go
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"math/big"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCommas(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"0", Comma(0), "0"},
|
||||||
|
{"10", Comma(10), "10"},
|
||||||
|
{"100", Comma(100), "100"},
|
||||||
|
{"1,000", Comma(1000), "1,000"},
|
||||||
|
{"10,000", Comma(10000), "10,000"},
|
||||||
|
{"100,000", Comma(100000), "100,000"},
|
||||||
|
{"10,000,000", Comma(10000000), "10,000,000"},
|
||||||
|
{"10,100,000", Comma(10100000), "10,100,000"},
|
||||||
|
{"10,010,000", Comma(10010000), "10,010,000"},
|
||||||
|
{"10,001,000", Comma(10001000), "10,001,000"},
|
||||||
|
{"123,456,789", Comma(123456789), "123,456,789"},
|
||||||
|
{"maxint", Comma(9.223372e+18), "9,223,372,000,000,000,000"},
|
||||||
|
{"minint", Comma(-9.223372e+18), "-9,223,372,000,000,000,000"},
|
||||||
|
{"-123,456,789", Comma(-123456789), "-123,456,789"},
|
||||||
|
{"-10,100,000", Comma(-10100000), "-10,100,000"},
|
||||||
|
{"-10,010,000", Comma(-10010000), "-10,010,000"},
|
||||||
|
{"-10,001,000", Comma(-10001000), "-10,001,000"},
|
||||||
|
{"-10,000,000", Comma(-10000000), "-10,000,000"},
|
||||||
|
{"-100,000", Comma(-100000), "-100,000"},
|
||||||
|
{"-10,000", Comma(-10000), "-10,000"},
|
||||||
|
{"-1,000", Comma(-1000), "-1,000"},
|
||||||
|
{"-100", Comma(-100), "-100"},
|
||||||
|
{"-10", Comma(-10), "-10"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCommafs(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"0", Commaf(0), "0"},
|
||||||
|
{"10.11", Commaf(10.11), "10.11"},
|
||||||
|
{"100", Commaf(100), "100"},
|
||||||
|
{"1,000", Commaf(1000), "1,000"},
|
||||||
|
{"10,000", Commaf(10000), "10,000"},
|
||||||
|
{"100,000", Commaf(100000), "100,000"},
|
||||||
|
{"834,142.32", Commaf(834142.32), "834,142.32"},
|
||||||
|
{"10,000,000", Commaf(10000000), "10,000,000"},
|
||||||
|
{"10,100,000", Commaf(10100000), "10,100,000"},
|
||||||
|
{"10,010,000", Commaf(10010000), "10,010,000"},
|
||||||
|
{"10,001,000", Commaf(10001000), "10,001,000"},
|
||||||
|
{"123,456,789", Commaf(123456789), "123,456,789"},
|
||||||
|
{"maxf64", Commaf(math.MaxFloat64), "179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000"},
|
||||||
|
{"minf64", Commaf(math.SmallestNonzeroFloat64), "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005"},
|
||||||
|
{"-123,456,789", Commaf(-123456789), "-123,456,789"},
|
||||||
|
{"-10,100,000", Commaf(-10100000), "-10,100,000"},
|
||||||
|
{"-10,010,000", Commaf(-10010000), "-10,010,000"},
|
||||||
|
{"-10,001,000", Commaf(-10001000), "-10,001,000"},
|
||||||
|
{"-10,000,000", Commaf(-10000000), "-10,000,000"},
|
||||||
|
{"-100,000", Commaf(-100000), "-100,000"},
|
||||||
|
{"-10,000", Commaf(-10000), "-10,000"},
|
||||||
|
{"-1,000", Commaf(-1000), "-1,000"},
|
||||||
|
{"-100.11", Commaf(-100.11), "-100.11"},
|
||||||
|
{"-10", Commaf(-10), "-10"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkCommas(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Comma(1234567890)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkCommaf(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
Commaf(1234567890.83584)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkBigCommas(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
BigComma(big.NewInt(1234567890))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func bigComma(i int64) string {
|
||||||
|
return BigComma(big.NewInt(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBigCommas(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"0", bigComma(0), "0"},
|
||||||
|
{"10", bigComma(10), "10"},
|
||||||
|
{"100", bigComma(100), "100"},
|
||||||
|
{"1,000", bigComma(1000), "1,000"},
|
||||||
|
{"10,000", bigComma(10000), "10,000"},
|
||||||
|
{"100,000", bigComma(100000), "100,000"},
|
||||||
|
{"10,000,000", bigComma(10000000), "10,000,000"},
|
||||||
|
{"10,100,000", bigComma(10100000), "10,100,000"},
|
||||||
|
{"10,010,000", bigComma(10010000), "10,010,000"},
|
||||||
|
{"10,001,000", bigComma(10001000), "10,001,000"},
|
||||||
|
{"123,456,789", bigComma(123456789), "123,456,789"},
|
||||||
|
{"maxint", bigComma(9.223372e+18), "9,223,372,000,000,000,000"},
|
||||||
|
{"minint", bigComma(-9.223372e+18), "-9,223,372,000,000,000,000"},
|
||||||
|
{"-123,456,789", bigComma(-123456789), "-123,456,789"},
|
||||||
|
{"-10,100,000", bigComma(-10100000), "-10,100,000"},
|
||||||
|
{"-10,010,000", bigComma(-10010000), "-10,010,000"},
|
||||||
|
{"-10,001,000", bigComma(-10001000), "-10,001,000"},
|
||||||
|
{"-10,000,000", bigComma(-10000000), "-10,000,000"},
|
||||||
|
{"-100,000", bigComma(-100000), "-100,000"},
|
||||||
|
{"-10,000", bigComma(-10000), "-10,000"},
|
||||||
|
{"-1,000", bigComma(-1000), "-1,000"},
|
||||||
|
{"-100", bigComma(-100), "-100"},
|
||||||
|
{"-10", bigComma(-10), "-10"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVeryBigCommas(t *testing.T) {
|
||||||
|
tests := []struct{ in, exp string }{
|
||||||
|
{
|
||||||
|
"84889279597249724975972597249849757294578485",
|
||||||
|
"84,889,279,597,249,724,975,972,597,249,849,757,294,578,485",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"-84889279597249724975972597249849757294578485",
|
||||||
|
"-84,889,279,597,249,724,975,972,597,249,849,757,294,578,485",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
n, _ := (&big.Int{}).SetString(test.in, 10)
|
||||||
|
got := BigComma(n)
|
||||||
|
if test.exp != got {
|
||||||
|
t.Errorf("Expected %q, got %q", test.exp, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
vendor/github.com/dustin/go-humanize/common_test.go
generated
vendored
Normal file
18
vendor/github.com/dustin/go-humanize/common_test.go
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testList []struct {
|
||||||
|
name, got, exp string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tl testList) validate(t *testing.T) {
|
||||||
|
for _, test := range tl {
|
||||||
|
if test.got != test.exp {
|
||||||
|
t.Errorf("On %v, expected '%v', but got '%v'",
|
||||||
|
test.name, test.exp, test.got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
vendor/github.com/dustin/go-humanize/ftoa_test.go
generated
vendored
Normal file
55
vendor/github.com/dustin/go-humanize/ftoa_test.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFtoa(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"200", Ftoa(200), "200"},
|
||||||
|
{"2", Ftoa(2), "2"},
|
||||||
|
{"2.2", Ftoa(2.2), "2.2"},
|
||||||
|
{"2.02", Ftoa(2.02), "2.02"},
|
||||||
|
{"200.02", Ftoa(200.02), "200.02"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkFtoaRegexTrailing(b *testing.B) {
|
||||||
|
trailingZerosRegex := regexp.MustCompile(`\.?0+$`)
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
trailingZerosRegex.ReplaceAllString("2.00000", "")
|
||||||
|
trailingZerosRegex.ReplaceAllString("2.0000", "")
|
||||||
|
trailingZerosRegex.ReplaceAllString("2.000", "")
|
||||||
|
trailingZerosRegex.ReplaceAllString("2.00", "")
|
||||||
|
trailingZerosRegex.ReplaceAllString("2.0", "")
|
||||||
|
trailingZerosRegex.ReplaceAllString("2", "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkFtoaFunc(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
stripTrailingZeros("2.00000")
|
||||||
|
stripTrailingZeros("2.0000")
|
||||||
|
stripTrailingZeros("2.000")
|
||||||
|
stripTrailingZeros("2.00")
|
||||||
|
stripTrailingZeros("2.0")
|
||||||
|
stripTrailingZeros("2")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkFmtF(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
fmt.Sprintf("%f", 2.03584)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkStrconvF(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
strconv.FormatFloat(2.03584, 'f', 6, 64)
|
||||||
|
}
|
||||||
|
}
|
||||||
78
vendor/github.com/dustin/go-humanize/number_test.go
generated
vendored
Normal file
78
vendor/github.com/dustin/go-humanize/number_test.go
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestStruct struct {
|
||||||
|
name string
|
||||||
|
format string
|
||||||
|
num float64
|
||||||
|
formatted string
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFormatFloat(t *testing.T) {
|
||||||
|
tests := []TestStruct{
|
||||||
|
{"default", "", 12345.6789, "12,345.68"},
|
||||||
|
{"#", "#", 12345.6789, "12345.678900000"},
|
||||||
|
{"#.", "#.", 12345.6789, "12346"},
|
||||||
|
{"#,#", "#,#", 12345.6789, "12345,7"},
|
||||||
|
{"#,##", "#,##", 12345.6789, "12345,68"},
|
||||||
|
{"#,###", "#,###", 12345.6789, "12345,679"},
|
||||||
|
{"#,###.", "#,###.", 12345.6789, "12,346"},
|
||||||
|
{"#,###.##", "#,###.##", 12345.6789, "12,345.68"},
|
||||||
|
{"#,###.###", "#,###.###", 12345.6789, "12,345.679"},
|
||||||
|
{"#,###.####", "#,###.####", 12345.6789, "12,345.6789"},
|
||||||
|
{"#.###,######", "#.###,######", 12345.6789, "12.345,678900"},
|
||||||
|
{"#\u202f###,##", "#\u202f###,##", 12345.6789, "12 345,68"},
|
||||||
|
|
||||||
|
// special cases
|
||||||
|
{"NaN", "#", math.NaN(), "NaN"},
|
||||||
|
{"+Inf", "#", math.Inf(1), "Infinity"},
|
||||||
|
{"-Inf", "#", math.Inf(-1), "-Infinity"},
|
||||||
|
{"signStr <= -0.000000001", "", -0.000000002, "-0.00"},
|
||||||
|
{"signStr = 0", "", 0, "0.00"},
|
||||||
|
{"Format directive must start with +", "+000", 12345.6789, "+12345.678900000"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
got := FormatFloat(test.format, test.num)
|
||||||
|
if got != test.formatted {
|
||||||
|
t.Errorf("On %v (%v, %v), got %v, wanted %v",
|
||||||
|
test.name, test.format, test.num, got, test.formatted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Test a single integer
|
||||||
|
got := FormatInteger("#", 12345)
|
||||||
|
if got != "12345.000000000" {
|
||||||
|
t.Errorf("On %v (%v, %v), got %v, wanted %v",
|
||||||
|
"integerTest", "#", 12345, got, "12345.000000000")
|
||||||
|
}
|
||||||
|
// Test the things that could panic
|
||||||
|
panictests := []TestStruct{
|
||||||
|
{"RenderFloat(): invalid positive sign directive", "-", 12345.6789, "12,345.68"},
|
||||||
|
{"RenderFloat(): thousands separator directive must be followed by 3 digit-specifiers", "0.01", 12345.6789, "12,345.68"},
|
||||||
|
}
|
||||||
|
for _, test := range panictests {
|
||||||
|
didPanic := false
|
||||||
|
var message interface{}
|
||||||
|
func() {
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if message = recover(); message != nil {
|
||||||
|
didPanic = true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// call the target function
|
||||||
|
_ = FormatFloat(test.format, test.num)
|
||||||
|
|
||||||
|
}()
|
||||||
|
if didPanic != true {
|
||||||
|
t.Errorf("On %v, should have panic and did not.",
|
||||||
|
test.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
22
vendor/github.com/dustin/go-humanize/ordinals_test.go
generated
vendored
Normal file
22
vendor/github.com/dustin/go-humanize/ordinals_test.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestOrdinals(t *testing.T) {
|
||||||
|
testList{
|
||||||
|
{"0", Ordinal(0), "0th"},
|
||||||
|
{"1", Ordinal(1), "1st"},
|
||||||
|
{"2", Ordinal(2), "2nd"},
|
||||||
|
{"3", Ordinal(3), "3rd"},
|
||||||
|
{"4", Ordinal(4), "4th"},
|
||||||
|
{"10", Ordinal(10), "10th"},
|
||||||
|
{"11", Ordinal(11), "11th"},
|
||||||
|
{"12", Ordinal(12), "12th"},
|
||||||
|
{"13", Ordinal(13), "13th"},
|
||||||
|
{"101", Ordinal(101), "101st"},
|
||||||
|
{"102", Ordinal(102), "102nd"},
|
||||||
|
{"103", Ordinal(103), "103rd"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
98
vendor/github.com/dustin/go-humanize/si_test.go
generated
vendored
Normal file
98
vendor/github.com/dustin/go-humanize/si_test.go
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSI(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
num float64
|
||||||
|
formatted string
|
||||||
|
}{
|
||||||
|
{"e-24", 1e-24, "1yF"},
|
||||||
|
{"e-21", 1e-21, "1zF"},
|
||||||
|
{"e-18", 1e-18, "1aF"},
|
||||||
|
{"e-15", 1e-15, "1fF"},
|
||||||
|
{"e-12", 1e-12, "1pF"},
|
||||||
|
{"e-12", 2.2345e-12, "2.2345pF"},
|
||||||
|
{"e-12", 2.23e-12, "2.23pF"},
|
||||||
|
{"e-11", 2.23e-11, "22.3pF"},
|
||||||
|
{"e-10", 2.2e-10, "220pF"},
|
||||||
|
{"e-9", 2.2e-9, "2.2nF"},
|
||||||
|
{"e-8", 2.2e-8, "22nF"},
|
||||||
|
{"e-7", 2.2e-7, "220nF"},
|
||||||
|
{"e-6", 2.2e-6, "2.2µF"},
|
||||||
|
{"e-6", 1e-6, "1µF"},
|
||||||
|
{"e-5", 2.2e-5, "22µF"},
|
||||||
|
{"e-4", 2.2e-4, "220µF"},
|
||||||
|
{"e-3", 2.2e-3, "2.2mF"},
|
||||||
|
{"e-2", 2.2e-2, "22mF"},
|
||||||
|
{"e-1", 2.2e-1, "220mF"},
|
||||||
|
{"e+0", 2.2e-0, "2.2F"},
|
||||||
|
{"e+0", 2.2, "2.2F"},
|
||||||
|
{"e+1", 2.2e+1, "22F"},
|
||||||
|
{"0", 0, "0F"},
|
||||||
|
{"e+1", 22, "22F"},
|
||||||
|
{"e+2", 2.2e+2, "220F"},
|
||||||
|
{"e+2", 220, "220F"},
|
||||||
|
{"e+3", 2.2e+3, "2.2kF"},
|
||||||
|
{"e+3", 2200, "2.2kF"},
|
||||||
|
{"e+4", 2.2e+4, "22kF"},
|
||||||
|
{"e+4", 22000, "22kF"},
|
||||||
|
{"e+5", 2.2e+5, "220kF"},
|
||||||
|
{"e+6", 2.2e+6, "2.2MF"},
|
||||||
|
{"e+6", 1e+6, "1MF"},
|
||||||
|
{"e+7", 2.2e+7, "22MF"},
|
||||||
|
{"e+8", 2.2e+8, "220MF"},
|
||||||
|
{"e+9", 2.2e+9, "2.2GF"},
|
||||||
|
{"e+10", 2.2e+10, "22GF"},
|
||||||
|
{"e+11", 2.2e+11, "220GF"},
|
||||||
|
{"e+12", 2.2e+12, "2.2TF"},
|
||||||
|
{"e+15", 2.2e+15, "2.2PF"},
|
||||||
|
{"e+18", 2.2e+18, "2.2EF"},
|
||||||
|
{"e+21", 2.2e+21, "2.2ZF"},
|
||||||
|
{"e+24", 2.2e+24, "2.2YF"},
|
||||||
|
|
||||||
|
// special case
|
||||||
|
{"1F", 1000 * 1000, "1MF"},
|
||||||
|
{"1F", 1e6, "1MF"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
got := SI(test.num, "F")
|
||||||
|
if got != test.formatted {
|
||||||
|
t.Errorf("On %v (%v), got %v, wanted %v",
|
||||||
|
test.name, test.num, got, test.formatted)
|
||||||
|
}
|
||||||
|
|
||||||
|
gotf, gotu, err := ParseSI(test.formatted)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error parsing %v (%v): %v", test.name, test.formatted, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if math.Abs(1-(gotf/test.num)) > 0.01 {
|
||||||
|
t.Errorf("On %v (%v), got %v, wanted %v (±%v)",
|
||||||
|
test.name, test.formatted, gotf, test.num,
|
||||||
|
math.Abs(1-(gotf/test.num)))
|
||||||
|
}
|
||||||
|
if gotu != "F" {
|
||||||
|
t.Errorf("On %v (%v), expected unit F, got %v",
|
||||||
|
test.name, test.formatted, gotu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse error
|
||||||
|
gotf, gotu, err := ParseSI("x1.21JW") // 1.21 jigga whats
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error on x1.21JW, got %v %v", gotf, gotu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkParseSI(b *testing.B) {
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
ParseSI("2.2346ZB")
|
||||||
|
}
|
||||||
|
}
|
||||||
71
vendor/github.com/dustin/go-humanize/times_test.go
generated
vendored
Normal file
71
vendor/github.com/dustin/go-humanize/times_test.go
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package humanize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPast(t *testing.T) {
|
||||||
|
now := time.Now().Unix()
|
||||||
|
testList{
|
||||||
|
{"now", Time(time.Unix(now, 0)), "now"},
|
||||||
|
{"1 second ago", Time(time.Unix(now-1, 0)), "1 second ago"},
|
||||||
|
{"12 seconds ago", Time(time.Unix(now-12, 0)), "12 seconds ago"},
|
||||||
|
{"30 seconds ago", Time(time.Unix(now-30, 0)), "30 seconds ago"},
|
||||||
|
{"45 seconds ago", Time(time.Unix(now-45, 0)), "45 seconds ago"},
|
||||||
|
{"1 minute ago", Time(time.Unix(now-63, 0)), "1 minute ago"},
|
||||||
|
{"15 minutes ago", Time(time.Unix(now-15*Minute, 0)), "15 minutes ago"},
|
||||||
|
{"1 hour ago", Time(time.Unix(now-63*Minute, 0)), "1 hour ago"},
|
||||||
|
{"2 hours ago", Time(time.Unix(now-2*Hour, 0)), "2 hours ago"},
|
||||||
|
{"21 hours ago", Time(time.Unix(now-21*Hour, 0)), "21 hours ago"},
|
||||||
|
{"1 day ago", Time(time.Unix(now-26*Hour, 0)), "1 day ago"},
|
||||||
|
{"2 days ago", Time(time.Unix(now-49*Hour, 0)), "2 days ago"},
|
||||||
|
{"3 days ago", Time(time.Unix(now-3*Day, 0)), "3 days ago"},
|
||||||
|
{"1 week ago (1)", Time(time.Unix(now-7*Day, 0)), "1 week ago"},
|
||||||
|
{"1 week ago (2)", Time(time.Unix(now-12*Day, 0)), "1 week ago"},
|
||||||
|
{"2 weeks ago", Time(time.Unix(now-15*Day, 0)), "2 weeks ago"},
|
||||||
|
{"1 month ago", Time(time.Unix(now-39*Day, 0)), "1 month ago"},
|
||||||
|
{"3 months ago", Time(time.Unix(now-99*Day, 0)), "3 months ago"},
|
||||||
|
{"1 year ago (1)", Time(time.Unix(now-365*Day, 0)), "1 year ago"},
|
||||||
|
{"1 year ago (1)", Time(time.Unix(now-400*Day, 0)), "1 year ago"},
|
||||||
|
{"2 years ago (1)", Time(time.Unix(now-548*Day, 0)), "2 years ago"},
|
||||||
|
{"2 years ago (2)", Time(time.Unix(now-725*Day, 0)), "2 years ago"},
|
||||||
|
{"2 years ago (3)", Time(time.Unix(now-800*Day, 0)), "2 years ago"},
|
||||||
|
{"3 years ago", Time(time.Unix(now-3*Year, 0)), "3 years ago"},
|
||||||
|
{"long ago", Time(time.Unix(now-LongTime, 0)), "a long while ago"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFuture(t *testing.T) {
|
||||||
|
now := time.Now().Unix()
|
||||||
|
testList{
|
||||||
|
{"now", Time(time.Unix(now, 0)), "now"},
|
||||||
|
{"1 second from now", Time(time.Unix(now+1, 0)), "1 second from now"},
|
||||||
|
{"12 seconds from now", Time(time.Unix(now+12, 0)), "12 seconds from now"},
|
||||||
|
{"30 seconds from now", Time(time.Unix(now+30, 0)), "30 seconds from now"},
|
||||||
|
{"45 seconds from now", Time(time.Unix(now+45, 0)), "45 seconds from now"},
|
||||||
|
{"15 minutes from now", Time(time.Unix(now+15*Minute, 0)), "15 minutes from now"},
|
||||||
|
{"2 hours from now", Time(time.Unix(now+2*Hour, 0)), "2 hours from now"},
|
||||||
|
{"21 hours from now", Time(time.Unix(now+21*Hour, 0)), "21 hours from now"},
|
||||||
|
{"1 day from now", Time(time.Unix(now+26*Hour, 0)), "1 day from now"},
|
||||||
|
{"2 days from now", Time(time.Unix(now+49*Hour, 0)), "2 days from now"},
|
||||||
|
{"3 days from now", Time(time.Unix(now+3*Day, 0)), "3 days from now"},
|
||||||
|
{"1 week from now (1)", Time(time.Unix(now+7*Day, 0)), "1 week from now"},
|
||||||
|
{"1 week from now (2)", Time(time.Unix(now+12*Day, 0)), "1 week from now"},
|
||||||
|
{"2 weeks from now", Time(time.Unix(now+15*Day, 0)), "2 weeks from now"},
|
||||||
|
{"1 month from now", Time(time.Unix(now+30*Day, 0)), "1 month from now"},
|
||||||
|
{"1 year from now", Time(time.Unix(now+365*Day, 0)), "1 year from now"},
|
||||||
|
{"2 years from now", Time(time.Unix(now+2*Year, 0)), "2 years from now"},
|
||||||
|
{"a while from now", Time(time.Unix(now+LongTime, 0)), "a long while from now"},
|
||||||
|
}.validate(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRange(t *testing.T) {
|
||||||
|
start := time.Time{}
|
||||||
|
end := time.Unix(math.MaxInt64, math.MaxInt64)
|
||||||
|
x := RelTime(start, end, "ago", "from now")
|
||||||
|
if x != "a long while from now" {
|
||||||
|
t.Errorf("Expected a long while from now, got %q", x)
|
||||||
|
}
|
||||||
|
}
|
||||||
0
internal/github.com/fatih/color/README.md → vendor/github.com/fatih/color/README.md
generated
vendored
0
internal/github.com/fatih/color/README.md → vendor/github.com/fatih/color/README.md
generated
vendored
4
internal/github.com/fatih/color/color.go → vendor/github.com/fatih/color/color.go
generated
vendored
4
internal/github.com/fatih/color/color.go → vendor/github.com/fatih/color/color.go
generated
vendored
@@ -6,8 +6,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/mc/internal/github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/minio/mc/internal/github.com/shiena/ansicolor"
|
"github.com/shiena/ansicolor"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NoColor defines if the output is colorized or not. It's dynamically set to
|
// NoColor defines if the output is colorized or not. It's dynamically set to
|
||||||
176
vendor/github.com/fatih/color/color_test.go
generated
vendored
Normal file
176
vendor/github.com/fatih/color/color_test.go
generated
vendored
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
package color
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/shiena/ansicolor"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Testing colors is kinda different. First we test for given colors and their
|
||||||
|
// escaped formatted results. Next we create some visual tests to be tested.
|
||||||
|
// Each visual test includes the color name to be compared.
|
||||||
|
func TestColor(t *testing.T) {
|
||||||
|
rb := new(bytes.Buffer)
|
||||||
|
Output = rb
|
||||||
|
|
||||||
|
testColors := []struct {
|
||||||
|
text string
|
||||||
|
code Attribute
|
||||||
|
}{
|
||||||
|
{text: "black", code: FgBlack},
|
||||||
|
{text: "red", code: FgRed},
|
||||||
|
{text: "green", code: FgGreen},
|
||||||
|
{text: "yellow", code: FgYellow},
|
||||||
|
{text: "blue", code: FgBlue},
|
||||||
|
{text: "magent", code: FgMagenta},
|
||||||
|
{text: "cyan", code: FgCyan},
|
||||||
|
{text: "white", code: FgWhite},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range testColors {
|
||||||
|
New(c.code).Print(c.text)
|
||||||
|
|
||||||
|
line, _ := rb.ReadString('\n')
|
||||||
|
scannedLine := fmt.Sprintf("%q", line)
|
||||||
|
colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", c.code, c.text)
|
||||||
|
escapedForm := fmt.Sprintf("%q", colored)
|
||||||
|
|
||||||
|
fmt.Printf("%s\t: %s\n", c.text, line)
|
||||||
|
|
||||||
|
if scannedLine != escapedForm {
|
||||||
|
t.Errorf("Expecting %s, got '%s'\n", escapedForm, scannedLine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoColor(t *testing.T) {
|
||||||
|
rb := new(bytes.Buffer)
|
||||||
|
Output = rb
|
||||||
|
|
||||||
|
testColors := []struct {
|
||||||
|
text string
|
||||||
|
code Attribute
|
||||||
|
}{
|
||||||
|
{text: "black", code: FgBlack},
|
||||||
|
{text: "red", code: FgRed},
|
||||||
|
{text: "green", code: FgGreen},
|
||||||
|
{text: "yellow", code: FgYellow},
|
||||||
|
{text: "blue", code: FgBlue},
|
||||||
|
{text: "magent", code: FgMagenta},
|
||||||
|
{text: "cyan", code: FgCyan},
|
||||||
|
{text: "white", code: FgWhite},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range testColors {
|
||||||
|
p := New(c.code)
|
||||||
|
p.DisableColor()
|
||||||
|
p.Print(c.text)
|
||||||
|
|
||||||
|
line, _ := rb.ReadString('\n')
|
||||||
|
if line != c.text {
|
||||||
|
t.Errorf("Expecting %s, got '%s'\n", c.text, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// global check
|
||||||
|
NoColor = true
|
||||||
|
defer func() {
|
||||||
|
NoColor = false
|
||||||
|
}()
|
||||||
|
for _, c := range testColors {
|
||||||
|
p := New(c.code)
|
||||||
|
p.Print(c.text)
|
||||||
|
|
||||||
|
line, _ := rb.ReadString('\n')
|
||||||
|
if line != c.text {
|
||||||
|
t.Errorf("Expecting %s, got '%s'\n", c.text, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestColorVisual(t *testing.T) {
|
||||||
|
// First Visual Test
|
||||||
|
fmt.Println("")
|
||||||
|
Output = ansicolor.NewAnsiColorWriter(os.Stdout)
|
||||||
|
|
||||||
|
New(FgRed).Printf("red\t")
|
||||||
|
New(BgRed).Print(" ")
|
||||||
|
New(FgRed, Bold).Println(" red")
|
||||||
|
|
||||||
|
New(FgGreen).Printf("green\t")
|
||||||
|
New(BgGreen).Print(" ")
|
||||||
|
New(FgGreen, Bold).Println(" green")
|
||||||
|
|
||||||
|
New(FgYellow).Printf("yellow\t")
|
||||||
|
New(BgYellow).Print(" ")
|
||||||
|
New(FgYellow, Bold).Println(" yellow")
|
||||||
|
|
||||||
|
New(FgBlue).Printf("blue\t")
|
||||||
|
New(BgBlue).Print(" ")
|
||||||
|
New(FgBlue, Bold).Println(" blue")
|
||||||
|
|
||||||
|
New(FgMagenta).Printf("magenta\t")
|
||||||
|
New(BgMagenta).Print(" ")
|
||||||
|
New(FgMagenta, Bold).Println(" magenta")
|
||||||
|
|
||||||
|
New(FgCyan).Printf("cyan\t")
|
||||||
|
New(BgCyan).Print(" ")
|
||||||
|
New(FgCyan, Bold).Println(" cyan")
|
||||||
|
|
||||||
|
New(FgWhite).Printf("white\t")
|
||||||
|
New(BgWhite).Print(" ")
|
||||||
|
New(FgWhite, Bold).Println(" white")
|
||||||
|
fmt.Println("")
|
||||||
|
|
||||||
|
// Second Visual test
|
||||||
|
Black("black")
|
||||||
|
Red("red")
|
||||||
|
Green("green")
|
||||||
|
Yellow("yellow")
|
||||||
|
Blue("blue")
|
||||||
|
Magenta("magenta")
|
||||||
|
Cyan("cyan")
|
||||||
|
White("white")
|
||||||
|
|
||||||
|
// Third visual test
|
||||||
|
fmt.Println()
|
||||||
|
Set(FgBlue)
|
||||||
|
fmt.Println("is this blue?")
|
||||||
|
Unset()
|
||||||
|
|
||||||
|
Set(FgMagenta)
|
||||||
|
fmt.Println("and this magenta?")
|
||||||
|
Unset()
|
||||||
|
|
||||||
|
// Fourth Visual test
|
||||||
|
fmt.Println()
|
||||||
|
blue := New(FgBlue).PrintlnFunc()
|
||||||
|
blue("blue text with custom print func")
|
||||||
|
|
||||||
|
red := New(FgRed).PrintfFunc()
|
||||||
|
red("red text with a printf func: %d\n", 123)
|
||||||
|
|
||||||
|
put := New(FgYellow).SprintFunc()
|
||||||
|
warn := New(FgRed).SprintFunc()
|
||||||
|
|
||||||
|
fmt.Fprintf(Output, "this is a %s and this is %s.\n", put("warning"), warn("error"))
|
||||||
|
|
||||||
|
info := New(FgWhite, BgGreen).SprintFunc()
|
||||||
|
fmt.Fprintf(Output, "this %s rocks!\n", info("package"))
|
||||||
|
|
||||||
|
// Fifth Visual Test
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
|
fmt.Fprintln(Output, BlackString("black"))
|
||||||
|
fmt.Fprintln(Output, RedString("red"))
|
||||||
|
fmt.Fprintln(Output, GreenString("green"))
|
||||||
|
fmt.Fprintln(Output, YellowString("yellow"))
|
||||||
|
fmt.Fprintln(Output, BlueString("blue"))
|
||||||
|
fmt.Fprintln(Output, MagentaString("magenta"))
|
||||||
|
fmt.Fprintln(Output, CyanString("cyan"))
|
||||||
|
fmt.Fprintln(Output, WhiteString("white"))
|
||||||
|
}
|
||||||
0
internal/github.com/fatih/color/doc.go → vendor/github.com/fatih/color/doc.go
generated
vendored
0
internal/github.com/fatih/color/doc.go → vendor/github.com/fatih/color/doc.go
generated
vendored
0
internal/github.com/fatih/structs/LICENSE → vendor/github.com/fatih/structs/LICENSE
generated
vendored
0
internal/github.com/fatih/structs/LICENSE → vendor/github.com/fatih/structs/LICENSE
generated
vendored
0
internal/github.com/fatih/structs/tags.go → vendor/github.com/fatih/structs/tags.go
generated
vendored
0
internal/github.com/fatih/structs/tags.go → vendor/github.com/fatih/structs/tags.go
generated
vendored
0
internal/github.com/minio/cli/LICENSE → vendor/github.com/minio/cli/LICENSE
generated
vendored
0
internal/github.com/minio/cli/LICENSE → vendor/github.com/minio/cli/LICENSE
generated
vendored
0
internal/github.com/minio/cli/README.md → vendor/github.com/minio/cli/README.md
generated
vendored
0
internal/github.com/minio/cli/README.md → vendor/github.com/minio/cli/README.md
generated
vendored
0
internal/github.com/minio/cli/app.go → vendor/github.com/minio/cli/app.go
generated
vendored
0
internal/github.com/minio/cli/app.go → vendor/github.com/minio/cli/app.go
generated
vendored
587
vendor/github.com/minio/cli/app_test.go
generated
vendored
Normal file
587
vendor/github.com/minio/cli/app_test.go
generated
vendored
Normal file
@@ -0,0 +1,587 @@
|
|||||||
|
package cli_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExampleApp() {
|
||||||
|
// set args for examples sake
|
||||||
|
os.Args = []string{"greet", "--name", "Jeremy"}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "greet"
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
|
||||||
|
}
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
fmt.Printf("Hello %v\n", c.String("name"))
|
||||||
|
}
|
||||||
|
app.Author = "Harrison"
|
||||||
|
app.Email = "harrison@lolwut.com"
|
||||||
|
app.Authors = []cli.Author{{Name: "Oliver Allen", Email: "oliver@toyshop.com"}}
|
||||||
|
app.Run(os.Args)
|
||||||
|
// Output:
|
||||||
|
// Hello Jeremy
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleAppSubcommand() {
|
||||||
|
// set args for examples sake
|
||||||
|
os.Args = []string{"say", "hi", "english", "--name", "Jeremy"}
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "say"
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "hello",
|
||||||
|
Aliases: []string{"hi"},
|
||||||
|
Usage: "use it to see a description",
|
||||||
|
Description: "This is how we describe hello the function",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "english",
|
||||||
|
Aliases: []string{"en"},
|
||||||
|
Usage: "sends a greeting in english",
|
||||||
|
Description: "greets someone in english",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "name",
|
||||||
|
Value: "Bob",
|
||||||
|
Usage: "Name of the person to greet",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
fmt.Println("Hello,", c.String("name"))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
// Output:
|
||||||
|
// Hello, Jeremy
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleAppHelp() {
|
||||||
|
// set args for examples sake
|
||||||
|
os.Args = []string{"greet", "h", "describeit"}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "greet"
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
|
||||||
|
}
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "describeit",
|
||||||
|
Aliases: []string{"d"},
|
||||||
|
Usage: "use it to see a description",
|
||||||
|
Description: "This is how we describe describeit the function",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
fmt.Printf("i like to describe things")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Run(os.Args)
|
||||||
|
// Output:
|
||||||
|
// NAME:
|
||||||
|
// describeit - use it to see a description
|
||||||
|
//
|
||||||
|
// USAGE:
|
||||||
|
// command describeit [arguments...]
|
||||||
|
//
|
||||||
|
// DESCRIPTION:
|
||||||
|
// This is how we describe describeit the function
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_Run(t *testing.T) {
|
||||||
|
s := ""
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
s = s + c.Args().First()
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Run([]string{"command", "foo"})
|
||||||
|
expect(t, err, nil)
|
||||||
|
err = app.Run([]string{"command", "bar"})
|
||||||
|
expect(t, err, nil)
|
||||||
|
expect(t, s, "foobar")
|
||||||
|
}
|
||||||
|
|
||||||
|
var commandAppTests = []struct {
|
||||||
|
name string
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{"foobar", true},
|
||||||
|
{"batbaz", true},
|
||||||
|
{"b", true},
|
||||||
|
{"f", true},
|
||||||
|
{"bat", false},
|
||||||
|
{"nothing", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_Command(t *testing.T) {
|
||||||
|
app := cli.NewApp()
|
||||||
|
fooCommand := cli.Command{Name: "foobar", Aliases: []string{"f"}}
|
||||||
|
batCommand := cli.Command{Name: "batbaz", Aliases: []string{"b"}}
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
fooCommand,
|
||||||
|
batCommand,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range commandAppTests {
|
||||||
|
expect(t, app.Command(test.name) != nil, test.expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_CommandWithArgBeforeFlags(t *testing.T) {
|
||||||
|
var parsedOption, firstArg string
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
command := cli.Command{
|
||||||
|
Name: "cmd",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "option", Value: "", Usage: "some option"},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
parsedOption = c.String("option")
|
||||||
|
firstArg = c.Args().First()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Commands = []cli.Command{command}
|
||||||
|
|
||||||
|
app.Run([]string{"", "cmd", "my-arg", "--option", "my-option"})
|
||||||
|
|
||||||
|
expect(t, parsedOption, "my-option")
|
||||||
|
expect(t, firstArg, "my-arg")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
|
||||||
|
var context *cli.Context
|
||||||
|
|
||||||
|
a := cli.NewApp()
|
||||||
|
a.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "foo",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
context = c
|
||||||
|
},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lang",
|
||||||
|
Value: "english",
|
||||||
|
Usage: "language for the greeting",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Before: func(_ *cli.Context) error { return nil },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})
|
||||||
|
|
||||||
|
expect(t, context.Args().Get(0), "abcd")
|
||||||
|
expect(t, context.String("lang"), "spanish")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_CommandWithFlagBeforeTerminator(t *testing.T) {
|
||||||
|
var parsedOption string
|
||||||
|
var args []string
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
command := cli.Command{
|
||||||
|
Name: "cmd",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "option", Value: "", Usage: "some option"},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
parsedOption = c.String("option")
|
||||||
|
args = c.Args()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Commands = []cli.Command{command}
|
||||||
|
|
||||||
|
app.Run([]string{"", "cmd", "my-arg", "--option", "my-option", "--", "--notARealFlag"})
|
||||||
|
|
||||||
|
expect(t, parsedOption, "my-option")
|
||||||
|
expect(t, args[0], "my-arg")
|
||||||
|
expect(t, args[1], "--")
|
||||||
|
expect(t, args[2], "--notARealFlag")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_CommandWithNoFlagBeforeTerminator(t *testing.T) {
|
||||||
|
var args []string
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
command := cli.Command{
|
||||||
|
Name: "cmd",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
args = c.Args()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Commands = []cli.Command{command}
|
||||||
|
|
||||||
|
app.Run([]string{"", "cmd", "my-arg", "--", "notAFlagAtAll"})
|
||||||
|
|
||||||
|
expect(t, args[0], "my-arg")
|
||||||
|
expect(t, args[1], "--")
|
||||||
|
expect(t, args[2], "notAFlagAtAll")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_Float64Flag(t *testing.T) {
|
||||||
|
var meters float64
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.Float64Flag{Name: "height", Value: 1.5, Usage: "Set the height, in meters"},
|
||||||
|
}
|
||||||
|
app.Action = func(c *cli.Context) {
|
||||||
|
meters = c.Float64("height")
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run([]string{"", "--height", "1.93"})
|
||||||
|
expect(t, meters, 1.93)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_ParseSliceFlags(t *testing.T) {
|
||||||
|
var parsedOption, firstArg string
|
||||||
|
var parsedIntSlice []int
|
||||||
|
var parsedStringSlice []string
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
command := cli.Command{
|
||||||
|
Name: "cmd",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.IntSliceFlag{Name: "p", Value: &cli.IntSlice{}, Usage: "set one or more ip addr"},
|
||||||
|
cli.StringSliceFlag{Name: "ip", Value: &cli.StringSlice{}, Usage: "set one or more ports to open"},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
parsedIntSlice = c.IntSlice("p")
|
||||||
|
parsedStringSlice = c.StringSlice("ip")
|
||||||
|
parsedOption = c.String("option")
|
||||||
|
firstArg = c.Args().First()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Commands = []cli.Command{command}
|
||||||
|
|
||||||
|
app.Run([]string{"", "cmd", "my-arg", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})
|
||||||
|
|
||||||
|
IntsEquals := func(a, b []int) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i, v := range a {
|
||||||
|
if v != b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
StrsEquals := func(a, b []string) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i, v := range a {
|
||||||
|
if v != b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
var expectedIntSlice = []int{22, 80}
|
||||||
|
var expectedStringSlice = []string{"8.8.8.8", "8.8.4.4"}
|
||||||
|
|
||||||
|
if !IntsEquals(parsedIntSlice, expectedIntSlice) {
|
||||||
|
t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !StrsEquals(parsedStringSlice, expectedStringSlice) {
|
||||||
|
t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_DefaultStdout(t *testing.T) {
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
if app.Writer != os.Stdout {
|
||||||
|
t.Error("Default output writer not set.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type mockWriter struct {
|
||||||
|
written []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fw *mockWriter) Write(p []byte) (n int, err error) {
|
||||||
|
if fw.written == nil {
|
||||||
|
fw.written = p
|
||||||
|
} else {
|
||||||
|
fw.written = append(fw.written, p...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fw *mockWriter) GetWritten() (b []byte) {
|
||||||
|
return fw.written
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_SetStdout(t *testing.T) {
|
||||||
|
w := &mockWriter{}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "test"
|
||||||
|
app.Writer = w
|
||||||
|
|
||||||
|
err := app.Run([]string{"help"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Run error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(w.written) == 0 {
|
||||||
|
t.Error("App did not write output to desired writer.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_BeforeFunc(t *testing.T) {
|
||||||
|
beforeRun, subcommandRun := false, false
|
||||||
|
beforeError := fmt.Errorf("fail")
|
||||||
|
var err error
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
app.Before = func(c *cli.Context) error {
|
||||||
|
beforeRun = true
|
||||||
|
s := c.String("opt")
|
||||||
|
if s == "fail" {
|
||||||
|
return beforeError
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "sub",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
subcommandRun = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "opt"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// run with the Before() func succeeding
|
||||||
|
err = app.Run([]string{"command", "--opt", "succeed", "sub"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Run error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if beforeRun == false {
|
||||||
|
t.Errorf("Before() not executed when expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
if subcommandRun == false {
|
||||||
|
t.Errorf("Subcommand not executed when expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset
|
||||||
|
beforeRun, subcommandRun = false, false
|
||||||
|
|
||||||
|
// run with the Before() func failing
|
||||||
|
err = app.Run([]string{"command", "--opt", "fail", "sub"})
|
||||||
|
|
||||||
|
// should be the same error produced by the Before func
|
||||||
|
if err != beforeError {
|
||||||
|
t.Errorf("Run error expected, but not received")
|
||||||
|
}
|
||||||
|
|
||||||
|
if beforeRun == false {
|
||||||
|
t.Errorf("Before() not executed when expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
if subcommandRun == true {
|
||||||
|
t.Errorf("Subcommand executed when NOT expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApp_AfterFunc(t *testing.T) {
|
||||||
|
afterRun, subcommandRun := false, false
|
||||||
|
afterError := fmt.Errorf("fail")
|
||||||
|
var err error
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
app.After = func(c *cli.Context) error {
|
||||||
|
afterRun = true
|
||||||
|
s := c.String("opt")
|
||||||
|
if s == "fail" {
|
||||||
|
return afterError
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "sub",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
subcommandRun = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "opt"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// run with the After() func succeeding
|
||||||
|
err = app.Run([]string{"command", "--opt", "succeed", "sub"})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Run error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if afterRun == false {
|
||||||
|
t.Errorf("After() not executed when expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
if subcommandRun == false {
|
||||||
|
t.Errorf("Subcommand not executed when expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset
|
||||||
|
afterRun, subcommandRun = false, false
|
||||||
|
|
||||||
|
// run with the Before() func failing
|
||||||
|
err = app.Run([]string{"command", "--opt", "fail", "sub"})
|
||||||
|
|
||||||
|
// should be the same error produced by the Before func
|
||||||
|
if err != afterError {
|
||||||
|
t.Errorf("Run error expected, but not received")
|
||||||
|
}
|
||||||
|
|
||||||
|
if afterRun == false {
|
||||||
|
t.Errorf("After() not executed when expected")
|
||||||
|
}
|
||||||
|
|
||||||
|
if subcommandRun == false {
|
||||||
|
t.Errorf("Subcommand not executed when expected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppNoHelpFlag(t *testing.T) {
|
||||||
|
oldFlag := cli.HelpFlag
|
||||||
|
defer func() {
|
||||||
|
cli.HelpFlag = oldFlag
|
||||||
|
}()
|
||||||
|
|
||||||
|
cli.HelpFlag = cli.BoolFlag{}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
err := app.Run([]string{"test", "-h"})
|
||||||
|
|
||||||
|
if err != flag.ErrHelp {
|
||||||
|
t.Errorf("expected error about missing help flag, but got: %s (%T)", err, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppHelpPrinter(t *testing.T) {
|
||||||
|
oldPrinter := cli.HelpPrinter
|
||||||
|
defer func() {
|
||||||
|
cli.HelpPrinter = oldPrinter
|
||||||
|
}()
|
||||||
|
|
||||||
|
var wasCalled = false
|
||||||
|
cli.HelpPrinter = func(template string, data interface{}) {
|
||||||
|
wasCalled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Run([]string{"-h"})
|
||||||
|
|
||||||
|
if wasCalled == false {
|
||||||
|
t.Errorf("Help printer expected to be called, but was not")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppVersionPrinter(t *testing.T) {
|
||||||
|
oldPrinter := cli.VersionPrinter
|
||||||
|
defer func() {
|
||||||
|
cli.VersionPrinter = oldPrinter
|
||||||
|
}()
|
||||||
|
|
||||||
|
var wasCalled = false
|
||||||
|
cli.VersionPrinter = func(c *cli.Context) {
|
||||||
|
wasCalled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
app := cli.NewApp()
|
||||||
|
ctx := cli.NewContext(app, nil, nil)
|
||||||
|
cli.ShowVersion(ctx)
|
||||||
|
|
||||||
|
if wasCalled == false {
|
||||||
|
t.Errorf("Version printer expected to be called, but was not")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppCommandNotFound(t *testing.T) {
|
||||||
|
beforeRun, subcommandRun := false, false
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
app.CommandNotFound = func(c *cli.Context, command string) {
|
||||||
|
beforeRun = true
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "bar",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
subcommandRun = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run([]string{"command", "foo"})
|
||||||
|
|
||||||
|
expect(t, beforeRun, true)
|
||||||
|
expect(t, subcommandRun, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGlobalFlagsInSubcommands(t *testing.T) {
|
||||||
|
subcommandRun := false
|
||||||
|
app := cli.NewApp()
|
||||||
|
|
||||||
|
app.Flags = []cli.Flag{
|
||||||
|
cli.BoolFlag{Name: "debug, d", Usage: "Enable debugging"},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "foo",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "bar",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
if c.GlobalBool("debug") {
|
||||||
|
subcommandRun = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run([]string{"command", "-d", "foo", "bar"})
|
||||||
|
|
||||||
|
expect(t, subcommandRun, true)
|
||||||
|
}
|
||||||
0
internal/github.com/minio/cli/bool.go → vendor/github.com/minio/cli/bool.go
generated
vendored
0
internal/github.com/minio/cli/bool.go → vendor/github.com/minio/cli/bool.go
generated
vendored
0
internal/github.com/minio/cli/cli.go → vendor/github.com/minio/cli/cli.go
generated
vendored
0
internal/github.com/minio/cli/cli.go → vendor/github.com/minio/cli/cli.go
generated
vendored
100
vendor/github.com/minio/cli/cli_test.go
generated
vendored
Normal file
100
vendor/github.com/minio/cli/cli_test.go
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
package cli_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Example() {
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "todo"
|
||||||
|
app.Usage = "task list on the command line"
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "add",
|
||||||
|
Aliases: []string{"a"},
|
||||||
|
Usage: "add a task to the list",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("added task: ", c.Args().First())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "complete",
|
||||||
|
Aliases: []string{"c"},
|
||||||
|
Usage: "complete a task on the list",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("completed task: ", c.Args().First())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExampleSubcommand() {
|
||||||
|
app := cli.NewApp()
|
||||||
|
app.Name = "say"
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "hello",
|
||||||
|
Aliases: []string{"hi"},
|
||||||
|
Usage: "use it to see a description",
|
||||||
|
Description: "This is how we describe hello the function",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "english",
|
||||||
|
Aliases: []string{"en"},
|
||||||
|
Usage: "sends a greeting in english",
|
||||||
|
Description: "greets someone in english",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "name",
|
||||||
|
Value: "Bob",
|
||||||
|
Usage: "Name of the person to greet",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("Hello, ", c.String("name"))
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
Name: "spanish",
|
||||||
|
Aliases: []string{"sp"},
|
||||||
|
Usage: "sends a greeting in spanish",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "surname",
|
||||||
|
Value: "Jones",
|
||||||
|
Usage: "Surname of the person to greet",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("Hola, ", c.String("surname"))
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
Name: "french",
|
||||||
|
Aliases: []string{"fr"},
|
||||||
|
Usage: "sends a greeting in french",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "nickname",
|
||||||
|
Value: "Stevie",
|
||||||
|
Usage: "Nickname of the person to greet",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("Bonjour, ", c.String("nickname"))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
Name: "bye",
|
||||||
|
Usage: "says goodbye",
|
||||||
|
Action: func(c *cli.Context) {
|
||||||
|
println("bye")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
0
internal/github.com/minio/cli/command.go → vendor/github.com/minio/cli/command.go
generated
vendored
0
internal/github.com/minio/cli/command.go → vendor/github.com/minio/cli/command.go
generated
vendored
49
vendor/github.com/minio/cli/command_test.go
generated
vendored
Normal file
49
vendor/github.com/minio/cli/command_test.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package cli_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCommandDoNotIgnoreFlags(t *testing.T) {
|
||||||
|
app := cli.NewApp()
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
test := []string{"blah", "blah", "-break"}
|
||||||
|
set.Parse(test)
|
||||||
|
|
||||||
|
c := cli.NewContext(app, set, set)
|
||||||
|
|
||||||
|
command := cli.Command{
|
||||||
|
Name: "test-cmd",
|
||||||
|
Aliases: []string{"tc"},
|
||||||
|
Usage: "this is for testing",
|
||||||
|
Description: "testing",
|
||||||
|
Action: func(_ *cli.Context) {},
|
||||||
|
}
|
||||||
|
err := command.Run(c)
|
||||||
|
|
||||||
|
expect(t, err.Error(), "flag provided but not defined: -break")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCommandIgnoreFlags(t *testing.T) {
|
||||||
|
app := cli.NewApp()
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
test := []string{"blah", "blah"}
|
||||||
|
set.Parse(test)
|
||||||
|
|
||||||
|
c := cli.NewContext(app, set, set)
|
||||||
|
|
||||||
|
command := cli.Command{
|
||||||
|
Name: "test-cmd",
|
||||||
|
Aliases: []string{"tc"},
|
||||||
|
Usage: "this is for testing",
|
||||||
|
Description: "testing",
|
||||||
|
Action: func(_ *cli.Context) {},
|
||||||
|
SkipFlagParsing: true,
|
||||||
|
}
|
||||||
|
err := command.Run(c)
|
||||||
|
|
||||||
|
expect(t, err, nil)
|
||||||
|
}
|
||||||
0
internal/github.com/minio/cli/context.go → vendor/github.com/minio/cli/context.go
generated
vendored
0
internal/github.com/minio/cli/context.go → vendor/github.com/minio/cli/context.go
generated
vendored
111
vendor/github.com/minio/cli/context_test.go
generated
vendored
Normal file
111
vendor/github.com/minio/cli/context_test.go
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package cli_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewContext(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Int("myflag", 12, "doc")
|
||||||
|
globalSet := flag.NewFlagSet("test", 0)
|
||||||
|
globalSet.Int("myflag", 42, "doc")
|
||||||
|
command := cli.Command{Name: "mycommand"}
|
||||||
|
c := cli.NewContext(nil, set, globalSet)
|
||||||
|
c.Command = command
|
||||||
|
expect(t, c.Int("myflag"), 12)
|
||||||
|
expect(t, c.GlobalInt("myflag"), 42)
|
||||||
|
expect(t, c.Command.Name, "mycommand")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_Int(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Int("myflag", 12, "doc")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
expect(t, c.Int("myflag"), 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_Duration(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Duration("myflag", time.Duration(12*time.Second), "doc")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
expect(t, c.Duration("myflag"), time.Duration(12*time.Second))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_String(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.String("myflag", "hello world", "doc")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
expect(t, c.String("myflag"), "hello world")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_Bool(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", false, "doc")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
expect(t, c.Bool("myflag"), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_BoolT(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", true, "doc")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
expect(t, c.BoolT("myflag"), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_Args(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", false, "doc")
|
||||||
|
c := cli.NewContext(nil, set, set)
|
||||||
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
|
expect(t, len(c.Args()), 2)
|
||||||
|
expect(t, c.Bool("myflag"), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_IsSet(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", false, "doc")
|
||||||
|
set.String("otherflag", "hello world", "doc")
|
||||||
|
globalSet := flag.NewFlagSet("test", 0)
|
||||||
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
|
c := cli.NewContext(nil, set, globalSet)
|
||||||
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
|
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
||||||
|
expect(t, c.IsSet("myflag"), true)
|
||||||
|
expect(t, c.IsSet("otherflag"), false)
|
||||||
|
expect(t, c.IsSet("bogusflag"), false)
|
||||||
|
expect(t, c.IsSet("myflagGlobal"), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_GlobalIsSet(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", false, "doc")
|
||||||
|
set.String("otherflag", "hello world", "doc")
|
||||||
|
globalSet := flag.NewFlagSet("test", 0)
|
||||||
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
|
globalSet.Bool("myflagGlobalUnset", true, "doc")
|
||||||
|
c := cli.NewContext(nil, set, globalSet)
|
||||||
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
|
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
||||||
|
expect(t, c.GlobalIsSet("myflag"), false)
|
||||||
|
expect(t, c.GlobalIsSet("otherflag"), false)
|
||||||
|
expect(t, c.GlobalIsSet("bogusflag"), false)
|
||||||
|
expect(t, c.GlobalIsSet("myflagGlobal"), true)
|
||||||
|
expect(t, c.GlobalIsSet("myflagGlobalUnset"), false)
|
||||||
|
expect(t, c.GlobalIsSet("bogusGlobal"), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_NumFlags(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", false, "doc")
|
||||||
|
set.String("otherflag", "hello world", "doc")
|
||||||
|
globalSet := flag.NewFlagSet("test", 0)
|
||||||
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
|
c := cli.NewContext(nil, set, globalSet)
|
||||||
|
set.Parse([]string{"--myflag", "--otherflag=foo"})
|
||||||
|
globalSet.Parse([]string{"--myflagGlobal"})
|
||||||
|
expect(t, c.NumFlags(), 2)
|
||||||
|
}
|
||||||
0
internal/github.com/minio/cli/duration.go → vendor/github.com/minio/cli/duration.go
generated
vendored
0
internal/github.com/minio/cli/duration.go → vendor/github.com/minio/cli/duration.go
generated
vendored
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user