mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-15 08:18:42 +01:00
* shell: fix s3.circuitBreaker help examples and error messages The help examples used -type count, but -type accepts Count and MB (as its flag description says), so both examples failed with "type not valid, only 'count' and 'bytes' are allowed", an error that names neither accepted value. Two other errors pointed at flags that do not exist: -max and -counts, where the flag is -values. Use -type Count in the examples, name Count and MB in the type error, and -values in the value errors. TestCircuitBreakerHelpExamplesRun runs every help example and fails on master for the two -type count lines. Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com> * shell: name the bad action and the -actions flag in s3.circuitBreaker The unknown-action error pointed at a nonexistent -action flag and echoed the whole -actions list instead of the action that was rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com> Co-authored-by: anant <170962632+antcybersec@users.noreply.github.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package shell
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// Every example in the s3.circuitBreaker help text has to run as written.
|
|
func TestCircuitBreakerHelpExamplesRun(t *testing.T) {
|
|
originalLoadConfig := LoadConfig
|
|
t.Cleanup(func() { LoadConfig = originalLoadConfig })
|
|
LoadConfig = func(*CommandEnv, string, string, *bytes.Buffer) error { return nil }
|
|
|
|
cmd := &commandS3CircuitBreaker{}
|
|
examples := 0
|
|
for _, line := range strings.Split(cmd.Help(), "\n") {
|
|
fields := strings.Fields(line)
|
|
if len(fields) == 0 || fields[0] != cmd.Name() {
|
|
continue
|
|
}
|
|
examples++
|
|
// Leave out -apply: it saves the result inside the filer.
|
|
var args []string
|
|
for _, f := range fields[1:] {
|
|
if f != "-apply" {
|
|
args = append(args, f)
|
|
}
|
|
}
|
|
var out bytes.Buffer
|
|
if err := cmd.Do(args, nil, &out); err != nil {
|
|
t.Errorf("%s: %v", strings.TrimSpace(line), err)
|
|
}
|
|
}
|
|
if examples == 0 {
|
|
t.Fatal("found no examples in the help text")
|
|
}
|
|
}
|
|
|
|
func TestCircuitBreakerInvalidActionError(t *testing.T) {
|
|
originalLoadConfig := LoadConfig
|
|
t.Cleanup(func() { LoadConfig = originalLoadConfig })
|
|
LoadConfig = func(*CommandEnv, string, string, *bytes.Buffer) error { return nil }
|
|
|
|
cmd := &commandS3CircuitBreaker{}
|
|
err := cmd.Do([]string{"-global", "-type", "Count", "-actions", "Read,Bogus", "-values", "1,2"}, nil, &bytes.Buffer{})
|
|
if err == nil {
|
|
t.Fatal("expected an error for an unknown action")
|
|
}
|
|
if msg := err.Error(); !strings.Contains(msg, "value(Bogus)") || !strings.Contains(msg, "flag[-actions]") {
|
|
t.Errorf("error should name the bad action and -actions: %v", err)
|
|
}
|
|
}
|