SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
package shell
import (
"bytes"
"flag"
"strings"
"testing"
)
// A command that parses flags must report a bad flag as an error. Returning
// nil makes a typo in a weed shell script or a master maintenance script look
// like a successful run that did nothing.
func TestCommandsReturnFlagParseErrors(t *testing.T) {
for _, c := range Commands {
t.Run(c.Name(), func(t *testing.T) {
// fs.meta.load parses every argument but the last as flags.
err, needsEnv := doWithoutCommandEnv(c, []string{"-notAFlagOfAnyCommand", "arg"})
if needsEnv {
t.Skip("uses the command environment before parsing any flags")
}
if err == nil {
t.Fatal("an unknown flag was reported as success")
}
if !strings.Contains(err.Error(), "flag provided but not defined") {
t.Skipf("rejects its arguments without parsing flags: %v", err)
}
})
}
}
// doWithoutCommandEnv runs c with a nil CommandEnv. A command that panics here
// used the environment before parsing flags, or takes no flags at all.
func doWithoutCommandEnv(c command, args []string) (err error, needsEnv bool) {
defer func() {
if recover() != nil {
needsEnv = true
}
}()
var out bytes.Buffer
return c.Do(args, nil, &out), false
}
func TestProcessEachCmdTreatsHelpAsSuccess(t *testing.T) {
Commands = append(Commands, &fakeCommand{name: "test.help.command", err: flag.ErrHelp})
t.Cleanup(func() { Commands = Commands[:len(Commands)-1] })
exit, err := processEachCmd("test.help.command -h", nil)
if exit || err != nil {
t.Errorf("-h must not count as a failure, got exit=%v err=%v", exit, err)
}
}