Merge pull request #979 from harshavardhana/pr_out_move_testing_into_its_own_package_test_and_probe_newerror_
Move testing into its own <package>_test, add probe.NewError() new changes
This commit is contained in:
+1
-1
@@ -64,7 +64,7 @@ func runAccessCmd(ctx *cli.Context) {
|
||||
config := mustGetMcConfig()
|
||||
acl := bucketACL(ctx.Args().First())
|
||||
if !acl.isValidBucketACL() {
|
||||
Fatal(probe.New(errInvalidACL{acl: acl.String()}))
|
||||
Fatal(probe.NewError(errInvalidACL{acl: acl.String()}))
|
||||
}
|
||||
for _, arg := range ctx.Args().Tail() {
|
||||
targetURL, err := getExpandedURL(arg, config.Aliases)
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ func isValidAliasName(aliasName string) bool {
|
||||
func aliasExpand(aliasedURL string, aliases map[string]string) (string, *probe.Error) {
|
||||
u, err := client.Parse(aliasedURL)
|
||||
if err != nil {
|
||||
return aliasedURL, probe.New(errInvalidURL{URL: aliasedURL})
|
||||
return aliasedURL, probe.NewError(errInvalidURL{URL: aliasedURL})
|
||||
}
|
||||
// proper URL
|
||||
if u.Host != "" {
|
||||
@@ -69,7 +69,7 @@ func aliasExpand(aliasedURL string, aliases map[string]string) (string, *probe.E
|
||||
trimmedURL := expandedURL + "/" + strings.TrimPrefix(strings.TrimPrefix(splits[1], "/"), "\\")
|
||||
u, err := client.Parse(trimmedURL)
|
||||
if err != nil {
|
||||
return aliasedURL, probe.New(errInvalidURL{URL: aliasedURL})
|
||||
return aliasedURL, probe.NewError(errInvalidURL{URL: aliasedURL})
|
||||
}
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -92,9 +92,9 @@ func doCatCmd(sourceURL string) *probe.Error {
|
||||
// stdout closed by the user. Gracefully exit.
|
||||
return nil
|
||||
}
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
default:
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
+3
-3
@@ -140,7 +140,7 @@ func putTargets(targetURLs []string, length int64, reader io.Reader) *probe.Erro
|
||||
func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error) {
|
||||
url, err := client.Parse(urlStr)
|
||||
if err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
switch url.Type {
|
||||
case client.Object: // Minio and S3 compatible cloud storage
|
||||
@@ -166,7 +166,7 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error)
|
||||
case client.Filesystem:
|
||||
return fs.New(urlStr)
|
||||
}
|
||||
return nil, probe.New(errInvalidURL{URL: urlStr})
|
||||
return nil, probe.NewError(errInvalidURL{URL: urlStr})
|
||||
}
|
||||
|
||||
// url2Stat - Returns client, config and its stat Content from the URL
|
||||
@@ -200,7 +200,7 @@ func isValidURL(url string) bool {
|
||||
|
||||
func url2Client(url string) (client.Client, *probe.Error) {
|
||||
if !isValidURL(url) {
|
||||
return nil, probe.New(errInvalidURL{URL: url})
|
||||
return nil, probe.NewError(errInvalidURL{URL: url})
|
||||
}
|
||||
urlconfig, err := getHostConfig(url)
|
||||
if err != nil {
|
||||
|
||||
+7
-7
@@ -81,7 +81,7 @@ func saveConfig(arg string, aliases []string) *probe.Error {
|
||||
}
|
||||
return writeConfig(config)
|
||||
default:
|
||||
return probe.New(errInvalidArgument{})
|
||||
return probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,13 +113,13 @@ func doConfig(arg string, aliases []string) (string, *probe.Error) {
|
||||
if arg == "alias" {
|
||||
return "Alias written to [" + configPath + "].", nil
|
||||
}
|
||||
return "", probe.New(errUnexpected{})
|
||||
return "", probe.NewError(errUnexpected{})
|
||||
}
|
||||
|
||||
// addAlias - add new aliases
|
||||
func addAlias(aliases []string) (quick.Config, *probe.Error) {
|
||||
if len(aliases) < 2 {
|
||||
return nil, probe.New(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
conf := newConfigV1()
|
||||
config, err := quick.New(conf)
|
||||
@@ -134,18 +134,18 @@ func addAlias(aliases []string) (quick.Config, *probe.Error) {
|
||||
aliasName := aliases[0]
|
||||
url := strings.TrimSuffix(aliases[1], "/")
|
||||
if strings.HasPrefix(aliasName, "http") {
|
||||
return nil, probe.New(errInvalidAliasName{name: aliasName})
|
||||
return nil, probe.NewError(errInvalidAliasName{name: aliasName})
|
||||
}
|
||||
if !strings.HasPrefix(url, "http") {
|
||||
return nil, probe.New(errInvalidURL{URL: url})
|
||||
return nil, probe.NewError(errInvalidURL{URL: url})
|
||||
}
|
||||
if !isValidAliasName(aliasName) {
|
||||
return nil, probe.New(errInvalidAliasName{name: aliasName})
|
||||
return nil, probe.NewError(errInvalidAliasName{name: aliasName})
|
||||
}
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV1)
|
||||
if _, ok := newConf.Aliases[aliasName]; ok {
|
||||
return nil, probe.New(errAliasExists{})
|
||||
return nil, probe.NewError(errAliasExists{})
|
||||
}
|
||||
newConf.Aliases[aliasName] = url
|
||||
newConfig, err := quick.New(newConf)
|
||||
|
||||
@@ -52,7 +52,7 @@ func getMcConfigDir() (string, *probe.Error) {
|
||||
}
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
return "", probe.New(err)
|
||||
return "", probe.NewError(err)
|
||||
}
|
||||
// For windows the path is slightly different
|
||||
switch runtime.GOOS {
|
||||
@@ -77,7 +77,7 @@ func createMcConfigDir() *probe.Error {
|
||||
return err.Trace()
|
||||
}
|
||||
if err := os.MkdirAll(p, 0700); err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func mustGetMcConfigPath() string {
|
||||
// getMcConfig - reads configuration file and returns config
|
||||
func getMcConfig() (*configV1, *probe.Error) {
|
||||
if !isMcConfigExists() {
|
||||
return nil, probe.New(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
|
||||
configFile, err := getMcConfigPath()
|
||||
|
||||
@@ -73,13 +73,13 @@ func checkCopySyntax(ctx *cli.Context) {
|
||||
/****** Generic rules *******/
|
||||
// Recursive URLs are not allowed in target.
|
||||
if isURLRecursive(tgtURL) {
|
||||
console.Fatalf("Recursive option is not supported for target ‘%s’ argument. %s\n", tgtURL, probe.New(errInvalidArgument{}))
|
||||
console.Fatalf("Recursive option is not supported for target ‘%s’ argument. %s\n", tgtURL, probe.NewError(errInvalidArgument{}))
|
||||
}
|
||||
// scope locally
|
||||
{
|
||||
url, err := client.Parse(tgtURL)
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to parse target ‘%s’ argument. %s\n", tgtURL, probe.New(err))
|
||||
console.Fatalf("Unable to parse target ‘%s’ argument. %s\n", tgtURL, probe.NewError(err))
|
||||
}
|
||||
if url.Host != "" {
|
||||
if url.Path == string(url.Separator) {
|
||||
@@ -104,7 +104,7 @@ func checkCopySyntax(ctx *cli.Context) {
|
||||
// checkCopySyntaxTypeA verifies if the source and target are valid file arguments.
|
||||
func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
|
||||
if len(srcURLs) != 1 {
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", probe.New(errInvalidArgument{}))
|
||||
console.Fatalf("Invalid number of source arguments to copy command. %s\n", probe.NewError(errInvalidArgument{}))
|
||||
}
|
||||
srcURL := srcURLs[0]
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
@@ -113,7 +113,7 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
|
||||
}
|
||||
if !srcContent.Type.IsRegular() {
|
||||
Fatal(probe.New(errSourceIsNotFile{URL: srcURL}))
|
||||
Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,14 +129,14 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
|
||||
}
|
||||
if !srcContent.Type.IsRegular() {
|
||||
Fatal(probe.New(errSourceIsNotFile{URL: srcURL}))
|
||||
Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL}))
|
||||
}
|
||||
|
||||
_, tgtContent, err := url2Stat(tgtURL)
|
||||
// Target exist?.
|
||||
if err == nil {
|
||||
if !tgtContent.Type.IsDir() {
|
||||
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
|
||||
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,13 +152,13 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) {
|
||||
Fatal(err)
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
Fatal(probe.New(errSourceIsNotDir{URL: srcURL}))
|
||||
Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL}))
|
||||
}
|
||||
_, tgtContent, err := url2Stat(tgtURL)
|
||||
// Target exist?.
|
||||
if err == nil {
|
||||
if !tgtContent.Type.IsDir() {
|
||||
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
|
||||
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
Fatal(err)
|
||||
if !srcContent.Type.IsDir() { // Ellipses is supported only for folders.
|
||||
Fatal(probe.New(errSourceIsNotDir{URL: srcURL}))
|
||||
Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL}))
|
||||
}
|
||||
} else { // Regular URL.
|
||||
_, srcContent, err := url2Stat(srcURL)
|
||||
@@ -180,7 +180,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
|
||||
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
|
||||
}
|
||||
if !srcContent.Type.IsRegular() {
|
||||
Fatal(probe.New(errSourceIsNotFile{URL: srcURL}))
|
||||
Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
|
||||
// Target exist?.
|
||||
if err == nil {
|
||||
if !tgtContent.Type.IsDir() {
|
||||
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
|
||||
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func prepareCopyURLsTypeA(sourceURL string, targetURL string) copyURLs {
|
||||
}
|
||||
if !sourceContent.Type.IsRegular() {
|
||||
// Source is not a regular file
|
||||
return copyURLs{Error: probe.New(errInvalidSource{URL: sourceURL})}
|
||||
return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})}
|
||||
}
|
||||
// All OK.. We can proceed. Type A
|
||||
sourceContent.Name = sourceURL
|
||||
@@ -250,19 +250,19 @@ func prepareCopyURLsTypeB(sourceURL string, targetURL string) copyURLs {
|
||||
}
|
||||
if !sourceContent.Type.IsRegular() {
|
||||
// Source is not a regular file.
|
||||
return copyURLs{Error: probe.New(errInvalidSource{URL: sourceURL})}
|
||||
return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})}
|
||||
}
|
||||
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a folder and exists.
|
||||
{
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
return copyURLs{Error: probe.New(errInvalidSource{URL: sourceURL})}
|
||||
return copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})}
|
||||
}
|
||||
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
return copyURLs{Error: probe.New(errInvalidTarget{URL: targetURL})}
|
||||
return copyURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})}
|
||||
}
|
||||
targetURLParse.Path = filepath.Join(targetURLParse.Path, filepath.Base(sourceURLParse.Path))
|
||||
return prepareCopyURLsTypeA(sourceURL, targetURLParse.String())
|
||||
@@ -277,7 +277,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
defer close(copyURLsCh)
|
||||
if !isURLRecursive(sourceURL) {
|
||||
// Source is not of recursive type.
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errSourceNotRecursive{URL: sourceURL})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errSourceNotRecursive{URL: sourceURL})}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
|
||||
if !sourceContent.Type.IsDir() {
|
||||
// Source is not a dir.
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errSourceIsNotDir{URL: sourceURL})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errSourceIsNotDir{URL: sourceURL})}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -311,13 +311,13 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
// All OK.. We can proceed. Type B: source is a file, target is a folder and exists.
|
||||
sourceURLParse, err := client.Parse(sourceURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errInvalidSource{URL: sourceURL})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceURL})}
|
||||
continue
|
||||
}
|
||||
|
||||
targetURLParse, err := client.Parse(targetURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errInvalidTarget{URL: targetURL})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ func prepareCopyURLsTypeC(sourceURL, targetURL string) <-chan copyURLs {
|
||||
sourceContentURL := sourceURLDelimited + sourceContentName
|
||||
sourceContentParse, err := client.Parse(sourceContentURL)
|
||||
if err != nil {
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errInvalidSource{URL: sourceContentName})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidSource{URL: sourceContentName})}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ func prepareCopyURLsTypeD(sourceURLs []string, targetURL string) <-chan copyURLs
|
||||
|
||||
if sourceURLs == nil {
|
||||
// Source list is empty.
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errSourceListEmpty{})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errSourceListEmpty{})}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ func prepareCopyURLs(sourceURLs []string, targetURL string) <-chan copyURLs {
|
||||
copyURLsCh <- cURLs
|
||||
}
|
||||
default:
|
||||
copyURLsCh <- copyURLs{Error: probe.New(errInvalidArgument{})}
|
||||
copyURLsCh <- copyURLs{Error: probe.NewError(errInvalidArgument{})}
|
||||
}
|
||||
}(sourceURLs, targetURL, copyURLsCh)
|
||||
|
||||
|
||||
@@ -63,11 +63,11 @@ func mustURLJoinPath(url1, url2 string) string {
|
||||
func urlJoinPath(url1, url2 string) (string, *probe.Error) {
|
||||
u1, err := client.Parse(url1)
|
||||
if err != nil {
|
||||
return "", probe.New(err)
|
||||
return "", probe.NewError(err)
|
||||
}
|
||||
u2, err := client.Parse(url2)
|
||||
if err != nil {
|
||||
return "", probe.New(err)
|
||||
return "", probe.NewError(err)
|
||||
}
|
||||
u1.Path = filepath.Join(u1.Path, u2.Path)
|
||||
return u1.String(), nil
|
||||
@@ -170,7 +170,7 @@ func doDiffObjects(firstURL, secondURL string, ch chan diff) {
|
||||
default:
|
||||
ch <- diff{
|
||||
message: "‘" + firstURL + "’ is not an object. Please report this bug with ‘--debug’ option.",
|
||||
err: probe.New(errNotAnObject{url: firstURL}),
|
||||
err: probe.NewError(errNotAnObject{url: firstURL}),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
+3
-3
@@ -37,7 +37,7 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) {
|
||||
{
|
||||
url, err := client.Parse(URL)
|
||||
if err != nil {
|
||||
return hostConfig{}, probe.New(err)
|
||||
return hostConfig{}, probe.NewError(err)
|
||||
}
|
||||
// No host matching or keys needed for filesystem requests
|
||||
if url.Type == client.Filesystem {
|
||||
@@ -50,12 +50,12 @@ func getHostConfig(URL string) (hostConfig, *probe.Error) {
|
||||
for globURL, hostCfg := range config.Hosts {
|
||||
match, err := filepath.Match(globURL, url.Host)
|
||||
if err != nil {
|
||||
return hostConfig{}, probe.New(errInvalidGlobURL{glob: globURL, request: URL})
|
||||
return hostConfig{}, probe.NewError(errInvalidGlobURL{glob: globURL, request: URL})
|
||||
}
|
||||
if match {
|
||||
return hostCfg, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return hostConfig{}, probe.New(errNoMatchingHost{})
|
||||
return hostConfig{}, probe.NewError(errNoMatchingHost{})
|
||||
}
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
|
||||
jsonData, err := json.Marshal(sURLs)
|
||||
if err != nil {
|
||||
session.Close()
|
||||
console.Fatalf("Unable to marshal URLs to JSON. %s\n", probe.New(err))
|
||||
console.Fatalf("Unable to marshal URLs to JSON. %s\n", probe.NewError(err))
|
||||
}
|
||||
fmt.Fprintln(dataFP, string(jsonData))
|
||||
scanBar(sURLs.SourceContent.Name)
|
||||
|
||||
+3
-3
@@ -96,13 +96,13 @@ func checkMirrorSyntax(ctx *cli.Context) {
|
||||
Fatal(err)
|
||||
|
||||
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
|
||||
Fatal(probe.New(errSourceIsNotDir{URL: srcURL}))
|
||||
Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL}))
|
||||
}
|
||||
for _, tgtURL := range tgtURLs {
|
||||
_, content, err := url2Stat(tgtURL)
|
||||
if err == nil {
|
||||
if !content.Type.IsDir() {
|
||||
Fatal(probe.New(errTargetIsNotDir{URL: tgtURL}))
|
||||
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func prepareMirrorURLs(sourceURL string, targetURLs []string) <-chan mirrorURLs
|
||||
}
|
||||
// if one of the targets is not dir exit
|
||||
if !targetContent.Type.IsDir() {
|
||||
mirrorURLsCh <- mirrorURLs{Error: probe.New(errInvalidTarget{URL: targetURL})}
|
||||
mirrorURLsCh <- mirrorURLs{Error: probe.NewError(errInvalidTarget{URL: targetURL})}
|
||||
return
|
||||
}
|
||||
// special case, be extremely careful before changing this behavior - will lead to data loss
|
||||
|
||||
+28
-28
@@ -36,7 +36,7 @@ type fsClient struct {
|
||||
// New - instantiate a new fs client
|
||||
func New(path string) (client.Client, *probe.Error) {
|
||||
if strings.TrimSpace(path) == "" {
|
||||
return nil, probe.New(client.EmptyPath{})
|
||||
return nil, probe.NewError(client.EmptyPath{})
|
||||
}
|
||||
return &fsClient{path: normalizePath(path)}, nil
|
||||
}
|
||||
@@ -60,17 +60,17 @@ func (f *fsClient) fsStat() (os.FileInfo, *probe.Error) {
|
||||
// Resolve symlinks
|
||||
fpath, err := filepath.EvalSymlinks(fpath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
st, err := os.Stat(fpath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil, probe.New(client.NotFound{Path: fpath})
|
||||
return nil, probe.NewError(client.NotFound{Path: fpath})
|
||||
}
|
||||
if err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
@@ -81,12 +81,12 @@ func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
objectPath := f.path
|
||||
if objectDir != "" {
|
||||
if err := os.MkdirAll(objectDir, 0700); err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
}
|
||||
fs, err := os.Create(objectPath)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
defer fs.Close()
|
||||
|
||||
@@ -94,14 +94,14 @@ func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
if size > 0 {
|
||||
_, err = io.CopyN(fs, data, int64(size))
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
} else {
|
||||
// size could be 0 for virtual files on certain filesystems
|
||||
// for example /proc, so read till EOF for such files
|
||||
_, err = io.Copy(fs, data)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -111,7 +111,7 @@ func (f *fsClient) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
func (f *fsClient) get() (io.ReadCloser, int64, *probe.Error) {
|
||||
body, err := os.Open(f.path)
|
||||
if err != nil {
|
||||
return nil, 0, probe.New(err)
|
||||
return nil, 0, probe.NewError(err)
|
||||
}
|
||||
{
|
||||
content, err := f.getFSMetadata()
|
||||
@@ -123,7 +123,7 @@ func (f *fsClient) get() (io.ReadCloser, int64, *probe.Error) {
|
||||
}
|
||||
|
||||
func (f *fsClient) PresignedGetObject(expires time.Duration, offset, length int64) (string, *probe.Error) {
|
||||
return "", probe.New(client.APINotImplemented{API: "PresignedGetObject"})
|
||||
return "", probe.NewError(client.APINotImplemented{API: "PresignedGetObject"})
|
||||
}
|
||||
|
||||
// GetObject download an full or part object from bucket
|
||||
@@ -131,7 +131,7 @@ func (f *fsClient) PresignedGetObject(expires time.Duration, offset, length int6
|
||||
// with errors getobject will return nil reader, length and typed errors
|
||||
func (f *fsClient) GetObject(offset, length int64) (io.ReadCloser, int64, *probe.Error) {
|
||||
if offset < 0 || length < 0 {
|
||||
return nil, 0, probe.New(client.InvalidRange{Offset: offset})
|
||||
return nil, 0, probe.NewError(client.InvalidRange{Offset: offset})
|
||||
}
|
||||
|
||||
tmppath := f.path
|
||||
@@ -144,22 +144,22 @@ func (f *fsClient) GetObject(offset, length int64) (io.ReadCloser, int64, *probe
|
||||
// Resolve symlinks
|
||||
_, err := filepath.EvalSymlinks(tmppath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil, length, probe.New(err)
|
||||
return nil, length, probe.NewError(err)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, length, probe.New(err)
|
||||
return nil, length, probe.NewError(err)
|
||||
}
|
||||
if offset == 0 && length == 0 {
|
||||
return f.get()
|
||||
}
|
||||
body, err := os.Open(f.path)
|
||||
if err != nil {
|
||||
return nil, length, probe.New(err)
|
||||
return nil, length, probe.NewError(err)
|
||||
|
||||
}
|
||||
_, err = io.CopyN(ioutil.Discard, body, int64(offset))
|
||||
if err != nil {
|
||||
return nil, length, probe.New(err)
|
||||
return nil, length, probe.NewError(err)
|
||||
}
|
||||
return body, length, nil
|
||||
}
|
||||
@@ -191,14 +191,14 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if os.IsNotExist(err) {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -207,7 +207,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -223,7 +223,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -244,14 +244,14 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if os.IsNotExist(err) {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(client.ISBrokenSymlink{Path: file.Name()}),
|
||||
Err: probe.NewError(client.ISBrokenSymlink{Path: file.Name()}),
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
if err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(err),
|
||||
Err: probe.NewError(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ func aclToPerm(acl string) os.FileMode {
|
||||
func (f *fsClient) MakeBucket() *probe.Error {
|
||||
err := os.MkdirAll(f.path, 0775)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -383,15 +383,15 @@ func (f *fsClient) MakeBucket() *probe.Error {
|
||||
// SetBucketACL - create a new bucket
|
||||
func (f *fsClient) SetBucketACL(acl string) *probe.Error {
|
||||
if !isValidBucketACL(acl) {
|
||||
return probe.New(client.InvalidACLType{ACL: acl})
|
||||
return probe.NewError(client.InvalidACLType{ACL: acl})
|
||||
}
|
||||
err := os.MkdirAll(f.path, aclToPerm(acl))
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
err = os.Chmod(f.path, aclToPerm(acl))
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+15
-14
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package fs
|
||||
package fs_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/minio/mc/pkg/client"
|
||||
"github.com/minio/mc/pkg/client/fs"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -40,7 +41,7 @@ func (s *MySuite) TestList(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
objectPath := filepath.Join(root, "object1")
|
||||
fsc, perr := New(objectPath)
|
||||
fsc, perr := fs.New(objectPath)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
data := "hello"
|
||||
@@ -50,13 +51,13 @@ func (s *MySuite) TestList(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
objectPath = filepath.Join(root, "object2")
|
||||
fsc, perr = New(objectPath)
|
||||
fsc, perr = fs.New(objectPath)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data)))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
fsc, perr = New(root)
|
||||
fsc, perr = fs.New(root)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
var contents []*client.Content
|
||||
@@ -75,13 +76,13 @@ func (s *MySuite) TestList(c *C) {
|
||||
}
|
||||
|
||||
objectPath = filepath.Join(root, "test1/newObject1")
|
||||
fsc, perr = New(objectPath)
|
||||
fsc, perr = fs.New(objectPath)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
perr = fsc.PutObject(int64(dataLen), bytes.NewReader([]byte(data)))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
fsc, perr = New(root)
|
||||
fsc, perr = fs.New(root)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
contents = nil
|
||||
@@ -103,7 +104,7 @@ func (s *MySuite) TestList(c *C) {
|
||||
c.Assert(content.Type.IsDir(), Equals, true)
|
||||
}
|
||||
|
||||
fsc, perr = New(root)
|
||||
fsc, perr = fs.New(root)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
contents = nil
|
||||
@@ -139,7 +140,7 @@ func (s *MySuite) TestPutBucket(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
bucketPath := filepath.Join(root, "bucket")
|
||||
fsc, perr := New(bucketPath)
|
||||
fsc, perr := fs.New(bucketPath)
|
||||
c.Assert(perr, IsNil)
|
||||
perr = fsc.MakeBucket()
|
||||
c.Assert(perr, IsNil)
|
||||
@@ -152,7 +153,7 @@ func (s *MySuite) TestStatBucket(c *C) {
|
||||
|
||||
bucketPath := filepath.Join(root, "bucket")
|
||||
|
||||
fsc, perr := New(bucketPath)
|
||||
fsc, perr := fs.New(bucketPath)
|
||||
c.Assert(perr, IsNil)
|
||||
perr = fsc.MakeBucket()
|
||||
c.Assert(perr, IsNil)
|
||||
@@ -166,7 +167,7 @@ func (s *MySuite) TestPutBucketACL(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
bucketPath := filepath.Join(root, "bucket")
|
||||
fsc, perr := New(bucketPath)
|
||||
fsc, perr := fs.New(bucketPath)
|
||||
c.Assert(perr, IsNil)
|
||||
perr = fsc.MakeBucket()
|
||||
c.Assert(perr, IsNil)
|
||||
@@ -181,7 +182,7 @@ func (s *MySuite) TestPutObject(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
objectPath := filepath.Join(root, "object")
|
||||
fsc, perr := New(objectPath)
|
||||
fsc, perr := fs.New(objectPath)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
data := "hello"
|
||||
@@ -197,7 +198,7 @@ func (s *MySuite) TestGetObject(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
objectPath := filepath.Join(root, "object")
|
||||
fsc, perr := New(objectPath)
|
||||
fsc, perr := fs.New(objectPath)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
data := "hello"
|
||||
@@ -221,7 +222,7 @@ func (s *MySuite) TestGetObjectRange(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
objectPath := filepath.Join(root, "object")
|
||||
fsc, perr := New(objectPath)
|
||||
fsc, perr := fs.New(objectPath)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
data := "hello world"
|
||||
@@ -244,7 +245,7 @@ func (s *MySuite) TestStatObject(c *C) {
|
||||
defer os.RemoveAll(root)
|
||||
|
||||
objectPath := filepath.Join(root, "object")
|
||||
fsc, perr := New(objectPath)
|
||||
fsc, perr := fs.New(objectPath)
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
data := "hello"
|
||||
|
||||
+18
-18
@@ -59,7 +59,7 @@ type s3Client struct {
|
||||
func New(config *Config) (client.Client, *probe.Error) {
|
||||
u, err := client.Parse(config.HostURL)
|
||||
if err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
var transport http.RoundTripper
|
||||
switch {
|
||||
@@ -81,7 +81,7 @@ func New(config *Config) (client.Client, *probe.Error) {
|
||||
s3Conf.Endpoint = u.Scheme + u.SchemeSeparator + u.Host
|
||||
api, err := minio.New(s3Conf)
|
||||
if err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
return &s3Client{api: api, hostURL: u}, nil
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (c *s3Client) GetObject(offset, length int64) (io.ReadCloser, int64, *probe
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
reader, metadata, err := c.api.GetPartialObject(bucket, object, offset, length)
|
||||
if err != nil {
|
||||
return nil, length, probe.New(err)
|
||||
return nil, length, probe.NewError(err)
|
||||
}
|
||||
return reader, metadata.Size, nil
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (c *s3Client) PresignedGetObject(expires time.Duration, offset, length int6
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
presignedURL, err := c.api.PresignedGetPartialObject(bucket, object, expires, offset, length)
|
||||
if err != nil {
|
||||
return "", probe.New(err)
|
||||
return "", probe.NewError(err)
|
||||
}
|
||||
return presignedURL, nil
|
||||
}
|
||||
@@ -122,10 +122,10 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
errResponse := minio.ToErrorResponse(err)
|
||||
if errResponse != nil {
|
||||
if errResponse.Code == "MethodNotAllowed" {
|
||||
return probe.New(client.ObjectAlreadyExists{Object: object})
|
||||
return probe.NewError(client.ObjectAlreadyExists{Object: object})
|
||||
}
|
||||
}
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -134,11 +134,11 @@ func (c *s3Client) PutObject(size int64, data io.Reader) *probe.Error {
|
||||
func (c *s3Client) MakeBucket() *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if object != "" {
|
||||
return probe.New(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.MakeBucket(bucket, minio.BucketACL("private"))
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -147,11 +147,11 @@ func (c *s3Client) MakeBucket() *probe.Error {
|
||||
func (c *s3Client) SetBucketACL(acl string) *probe.Error {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if object != "" {
|
||||
return probe.New(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
return probe.NewError(client.InvalidQueryURL{URL: c.hostURL.String()})
|
||||
}
|
||||
err := c.api.SetBucketACL(bucket, minio.BucketACL(acl))
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) {
|
||||
case bucket == "" && object == "":
|
||||
for bucket := range c.api.ListBuckets() {
|
||||
if bucket.Err != nil {
|
||||
return nil, probe.New(bucket.Err)
|
||||
return nil, probe.NewError(bucket.Err)
|
||||
}
|
||||
return &client.Content{Type: os.ModeDir}, nil
|
||||
}
|
||||
@@ -187,7 +187,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
objectMetadata.Name = metadata.Key
|
||||
objectMetadata.Time = metadata.LastModified
|
||||
@@ -197,7 +197,7 @@ func (c *s3Client) Stat() (*client.Content, *probe.Error) {
|
||||
}
|
||||
err := c.api.BucketExists(bucket)
|
||||
if err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
bucketMetadata := new(client.Content)
|
||||
bucketMetadata.Name = bucket
|
||||
@@ -253,7 +253,7 @@ func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if bucket.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(bucket.Err),
|
||||
Err: probe.NewError(bucket.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func (c *s3Client) listInRoutine(contentCh chan client.ContentOnChannel) {
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(object.Err),
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -323,7 +323,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
if bucket.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(bucket.Err),
|
||||
Err: probe.NewError(bucket.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(object.Err),
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -351,7 +351,7 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
|
||||
if object.Err != nil {
|
||||
contentCh <- client.ContentOnChannel{
|
||||
Content: nil,
|
||||
Err: probe.New(object.Err),
|
||||
Err: probe.NewError(object.Err),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ func Unlock() {
|
||||
// SetTheme sets a color theme
|
||||
func SetTheme(themeName string) *probe.Error {
|
||||
if !IsValidTheme(themeName) {
|
||||
return probe.New(fmt.Errorf("Unsupported theme name [%s]", themeName))
|
||||
return probe.NewError(fmt.Errorf("Unsupported theme name [%s]", themeName))
|
||||
}
|
||||
|
||||
mutex.Lock()
|
||||
|
||||
+33
-3
@@ -66,11 +66,11 @@ type Error struct {
|
||||
tracePoints []tracePoint
|
||||
}
|
||||
|
||||
// New function instantiates an error probe for tracing. Original errors.error (golang's error
|
||||
// NewError function instantiates an error probe for tracing. Original errors.error (golang's error
|
||||
// interface) is injected in only once during this New call. Rest of the time, you
|
||||
// trace the return path with Probe.Trace and finally handle reporting or quitting
|
||||
// at the top level.
|
||||
func New(e error) *Error {
|
||||
func NewError(e error) *Error {
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -179,8 +179,38 @@ func (e *Error) JSON() string {
|
||||
return string(jBytes)
|
||||
}
|
||||
|
||||
// ToError returns original emnedded error.
|
||||
// ToError returns original embedded error.
|
||||
func (e *Error) ToError() error {
|
||||
// No need to lock. "e.e" is set once during New and never changed.
|
||||
return e.e
|
||||
}
|
||||
|
||||
// WrappedError implements container for *probe.Error
|
||||
type WrappedError struct {
|
||||
err *Error
|
||||
}
|
||||
|
||||
// NewWrappedError function wraps a *probe.Error into a 'error' compatible duck type
|
||||
func NewWrappedError(err *Error) error {
|
||||
return &WrappedError{err: err}
|
||||
}
|
||||
|
||||
// Error interface method
|
||||
func (w *WrappedError) Error() string {
|
||||
return w.err.String()
|
||||
}
|
||||
|
||||
// ToError get the *probe.Error embedded internally
|
||||
func (w *WrappedError) ToError() *Error {
|
||||
return w.err
|
||||
}
|
||||
|
||||
// ToWrappedError try to convert generic 'error' into typed *WrappedError, returns true if yes, false otherwise
|
||||
func ToWrappedError(err error) (*WrappedError, bool) {
|
||||
switch e := err.(type) {
|
||||
case *WrappedError:
|
||||
return e, true
|
||||
default:
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
|
||||
+25
-17
@@ -13,33 +13,41 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package probe
|
||||
package probe_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func testDummy() *Error {
|
||||
_, e := os.Stat("this-file-cannot-exit-234234232423423")
|
||||
es := New(e)
|
||||
es.Trace("this is hell", "asdf")
|
||||
func Test(t *testing.T) { TestingT(t) }
|
||||
|
||||
type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func testDummy() *probe.Error {
|
||||
_, e := os.Stat("this-file-cannot-exit")
|
||||
es := probe.NewError(e)
|
||||
es.Trace("Important info 1", "Import into 2")
|
||||
return es
|
||||
}
|
||||
|
||||
func TestProbe(t *testing.T) {
|
||||
func (s *MySuite) TestProbe(c *C) {
|
||||
es := testDummy()
|
||||
if es == nil {
|
||||
t.Fail()
|
||||
}
|
||||
c.Assert(es, Not(Equals), nil)
|
||||
|
||||
newES := es.Trace()
|
||||
if newES == nil {
|
||||
t.Fail()
|
||||
}
|
||||
/*
|
||||
fmt.Println(es)
|
||||
fmt.Println(es.JSON())
|
||||
fmt.Println(es.ToError())
|
||||
*/
|
||||
c.Assert(newES, Not(Equals), nil)
|
||||
}
|
||||
|
||||
func (s *MySuite) TestWrappedError(c *C) {
|
||||
_, e := os.Stat("this-file-cannot-exit")
|
||||
es := probe.NewError(e) // *probe.Error
|
||||
e = probe.NewWrappedError(es) // *probe.WrappedError
|
||||
_, ok := probe.ToWrappedError(e)
|
||||
c.Assert(ok, Equals, true)
|
||||
}
|
||||
|
||||
+10
-10
@@ -52,17 +52,17 @@ type config struct {
|
||||
// CheckData - checks the validity of config data. Data sould be of type struct and contain a string type field called "Version"
|
||||
func CheckData(data interface{}) *probe.Error {
|
||||
if !structs.IsStruct(data) {
|
||||
return probe.New(fmt.Errorf("Invalid argument type. Expecing \"struct\" type."))
|
||||
return probe.NewError(fmt.Errorf("Invalid argument type. Expecing \"struct\" type."))
|
||||
}
|
||||
|
||||
st := structs.New(data)
|
||||
f, ok := st.FieldOk("Version")
|
||||
if !ok {
|
||||
return probe.New(fmt.Errorf("Invalid type of struct argument. No [%s.Version] field found.", st.Name()))
|
||||
return probe.NewError(fmt.Errorf("Invalid type of struct argument. No [%s.Version] field found.", st.Name()))
|
||||
}
|
||||
|
||||
if f.Kind() != reflect.String {
|
||||
return probe.New(fmt.Errorf("Invalid type of struct argument. Expecting \"string\" type [%s.Version] field.", st.Name()))
|
||||
return probe.NewError(fmt.Errorf("Invalid type of struct argument. Expecting \"string\" type [%s.Version] field.", st.Name()))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -111,7 +111,7 @@ func (d config) Save(filename string) *probe.Error {
|
||||
|
||||
jsonData, err := json.MarshalIndent(d.data, "", "\t")
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
@@ -120,7 +120,7 @@ func (d config) Save(filename string) *probe.Error {
|
||||
|
||||
err = ioutil.WriteFile(filename, jsonData, 0600)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -133,12 +133,12 @@ func (d *config) Load(filename string) *probe.Error {
|
||||
|
||||
_, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
fileData, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
@@ -147,7 +147,7 @@ func (d *config) Load(filename string) *probe.Error {
|
||||
|
||||
err = json.Unmarshal(fileData, (*d).data)
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
if err := CheckData(*(*d).data); err != nil {
|
||||
@@ -157,11 +157,11 @@ func (d *config) Load(filename string) *probe.Error {
|
||||
st := structs.New(*(*d).data)
|
||||
f, ok := st.FieldOk("Version")
|
||||
if !ok {
|
||||
return probe.New(fmt.Errorf("Argument struct [%s] does not contain field \"Version\".", st.Name()))
|
||||
return probe.NewError(fmt.Errorf("Argument struct [%s] does not contain field \"Version\".", st.Name()))
|
||||
}
|
||||
|
||||
if (*d).Version() != f.Value() {
|
||||
return probe.New(fmt.Errorf("Version mismatch"))
|
||||
return probe.NewError(fmt.Errorf("Version mismatch"))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+11
-10
@@ -16,12 +16,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package quick
|
||||
package quick_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/mc/pkg/quick"
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@@ -32,7 +33,7 @@ type MySuite struct{}
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) TestCheckData(c *C) {
|
||||
err := CheckData(nil)
|
||||
err := quick.CheckData(nil)
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
type myStructBad struct {
|
||||
@@ -41,7 +42,7 @@ func (s *MySuite) TestCheckData(c *C) {
|
||||
Folders []string
|
||||
}
|
||||
saveMeBad := myStructBad{"guest", "nopassword", []string{"Work", "Documents", "Music"}}
|
||||
err = CheckData(&saveMeBad)
|
||||
err = quick.CheckData(&saveMeBad)
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
type myStructGood struct {
|
||||
@@ -52,7 +53,7 @@ func (s *MySuite) TestCheckData(c *C) {
|
||||
}
|
||||
|
||||
saveMeGood := myStructGood{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
|
||||
err = CheckData(&saveMeGood)
|
||||
err = quick.CheckData(&saveMeGood)
|
||||
c.Assert(err, IsNil)
|
||||
}
|
||||
|
||||
@@ -65,13 +66,13 @@ func (s *MySuite) TestSaveLoad(c *C) {
|
||||
Folders []string
|
||||
}
|
||||
saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
|
||||
config, err := New(&saveMe)
|
||||
config, err := quick.New(&saveMe)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(config, Not(IsNil))
|
||||
config.Save("test.json")
|
||||
|
||||
loadMe := myStruct{Version: "1"}
|
||||
newConfig, err := New(&loadMe)
|
||||
newConfig, err := quick.New(&loadMe)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(newConfig, Not(IsNil))
|
||||
newConfig.Load("test.json")
|
||||
@@ -91,7 +92,7 @@ func (s *MySuite) TestDiff(c *C) {
|
||||
Folders []string
|
||||
}
|
||||
saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
|
||||
config, err := New(&saveMe)
|
||||
config, err := quick.New(&saveMe)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(config, Not(IsNil))
|
||||
|
||||
@@ -103,7 +104,7 @@ func (s *MySuite) TestDiff(c *C) {
|
||||
}
|
||||
|
||||
mismatch := myNewStruct{"1", "nopassword", []string{"Work", "documents", "Music"}}
|
||||
newConfig, err := New(&mismatch)
|
||||
newConfig, err := quick.New(&mismatch)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(newConfig, Not(IsNil))
|
||||
|
||||
@@ -125,12 +126,12 @@ func (s *MySuite) TestDeepDiff(c *C) {
|
||||
Folders []string
|
||||
}
|
||||
saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
|
||||
config, err := New(&saveMe)
|
||||
config, err := quick.New(&saveMe)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(config, Not(IsNil))
|
||||
|
||||
mismatch := myStruct{"1", "Guest", "nopassword", []string{"Work", "documents", "Music"}}
|
||||
newConfig, err := New(&mismatch)
|
||||
newConfig, err := quick.New(&mismatch)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(newConfig, Not(IsNil))
|
||||
|
||||
|
||||
+3
-3
@@ -50,12 +50,12 @@ func (s sessionV1) String() string {
|
||||
// loadSession - reads session file if exists and re-initiates internal variables
|
||||
func loadSessionV1(sid string) (*sessionV1, *probe.Error) {
|
||||
if !isSessionDirExists() {
|
||||
return nil, probe.New(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
sessionFile := getSessionFileV1(sid)
|
||||
|
||||
if _, err := os.Stat(sessionFile); err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
s := new(sessionV1)
|
||||
s.Version = "1.0.0"
|
||||
@@ -77,7 +77,7 @@ func loadSessionV1(sid string) (*sessionV1, *probe.Error) {
|
||||
func getSessionIDsV1() (sids []string) {
|
||||
sessionList, err := filepath.Glob(getSessionDir() + "/*")
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.New(err))
|
||||
console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.NewError(err))
|
||||
}
|
||||
|
||||
for _, path := range sessionList {
|
||||
|
||||
+9
-9
@@ -35,7 +35,7 @@ func migrateSessionV1ToV2() {
|
||||
for _, sid := range getSessionIDsV1() {
|
||||
err := os.Remove(getSessionFileV1(sid))
|
||||
if err != nil {
|
||||
console.Fatalf("Migration failed. Unable to remove old session file %s. %s\n", getSessionFileV1(sid), probe.New(err))
|
||||
console.Fatalf("Migration failed. Unable to remove old session file %s. %s\n", getSessionFileV1(sid), probe.NewError(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func (s *sessionV2) Save() *probe.Error {
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
if err := s.DataFP.Sync(); err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
qs, err := quick.New(s.Header)
|
||||
@@ -129,7 +129,7 @@ func (s *sessionV2) Close() *probe.Error {
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
if err := s.DataFP.Close(); err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
qs, err := quick.New(s.Header)
|
||||
@@ -148,17 +148,17 @@ func (s *sessionV2) Delete() *probe.Error {
|
||||
if s.DataFP != nil {
|
||||
err := os.Remove(s.DataFP.Name())
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
}
|
||||
|
||||
err := os.Remove(getSessionFile(s.SessionID))
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -167,12 +167,12 @@ func (s *sessionV2) Delete() *probe.Error {
|
||||
// loadSession - reads session file if exists and re-initiates internal variables
|
||||
func loadSessionV2(sid string) (*sessionV2, *probe.Error) {
|
||||
if !isSessionDirExists() {
|
||||
return nil, probe.New(errInvalidArgument{})
|
||||
return nil, probe.NewError(errInvalidArgument{})
|
||||
}
|
||||
sessionFile := getSessionFile(sid)
|
||||
|
||||
if _, err := os.Stat(sessionFile); err != nil {
|
||||
return nil, probe.New(err)
|
||||
return nil, probe.NewError(err)
|
||||
}
|
||||
|
||||
s := &sessionV2{}
|
||||
@@ -209,7 +209,7 @@ func isCopiedFactory(lastCopied string) func(string) bool {
|
||||
copied := true // closure
|
||||
return func(sourceURL string) bool {
|
||||
if sourceURL == "" {
|
||||
console.Fatalf("Empty source URL passed to isCopied() function. %s\n", probe.New(errUnexpected{}))
|
||||
console.Fatalf("Empty source URL passed to isCopied() function. %s\n", probe.NewError(errUnexpected{}))
|
||||
}
|
||||
if lastCopied == "" {
|
||||
return false
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ func isSessionDirExists() bool {
|
||||
|
||||
func createSessionDir() *probe.Error {
|
||||
if err := os.MkdirAll(getSessionDir(), 0700); err != nil {
|
||||
return probe.New(err)
|
||||
return probe.NewError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func getSessionDataFile(sid string) string {
|
||||
func getSessionIDs() (sids []string) {
|
||||
sessionList, err := filepath.Glob(getSessionDir() + "/*.json")
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.New(err))
|
||||
console.Fatalf("Unable to list session folder ‘%s’, %s", getSessionDir(), probe.NewError(err))
|
||||
}
|
||||
|
||||
for _, path := range sessionList {
|
||||
|
||||
+3
-3
@@ -71,7 +71,7 @@ func runShareCmd(ctx *cli.Context) {
|
||||
if len(args) == 2 {
|
||||
var err error
|
||||
expires, err = time.ParseDuration(args.Last())
|
||||
Fatal(probe.New(err))
|
||||
Fatal(probe.NewError(err))
|
||||
}
|
||||
targetURL, err := getExpandedURL(url, config.Aliases)
|
||||
Fatal(err)
|
||||
@@ -97,10 +97,10 @@ func doShareCmd(targetURL string, recursive bool, expires time.Duration) *probe.
|
||||
return err.Trace()
|
||||
}
|
||||
if expires.Seconds() < 1 {
|
||||
return probe.New(errors.New("Too low expires, expiration cannot be less than 1 second"))
|
||||
return probe.NewError(errors.New("Too low expires, expiration cannot be less than 1 second"))
|
||||
}
|
||||
if expires.Seconds() > 604800 {
|
||||
return probe.New(errors.New("Too high expires, expiration cannot be larger than 7 days"))
|
||||
return probe.NewError(errors.New("Too high expires, expiration cannot be larger than 7 days"))
|
||||
}
|
||||
for contentCh := range clnt.List(recursive) {
|
||||
if contentCh.Err != nil {
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ https://dl.minio.io:9000 for continuous updates`
|
||||
var updates Updates
|
||||
decoder := json.NewDecoder(data)
|
||||
if err := decoder.Decode(&updates); err != nil {
|
||||
return "Unable to parse update fields", probe.New(err)
|
||||
return "Unable to parse update fields", probe.NewError(err)
|
||||
}
|
||||
latest, _ := time.Parse(http.TimeFormat, updates.BuildDate)
|
||||
if latest.IsZero() {
|
||||
@@ -89,7 +89,7 @@ https://dl.minio.io:9000 for continuous updates`
|
||||
}
|
||||
msg, err := printUpdateNotify(updateString, "new", "old")
|
||||
if err != nil {
|
||||
return "", probe.New(err)
|
||||
return "", probe.NewError(err)
|
||||
}
|
||||
console.Println(msg)
|
||||
return "", nil
|
||||
|
||||
@@ -54,7 +54,7 @@ func getExpandedURL(arg string, aliases map[string]string) (urlStr string, err *
|
||||
}
|
||||
if _, err := client.Parse(urlStr); err != nil {
|
||||
// Not a valid URL. Return error
|
||||
return "", probe.New(errInvalidURL{urlStr})
|
||||
return "", probe.NewError(errInvalidURL{urlStr})
|
||||
}
|
||||
return urlStr, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user