Files
s3/weed/shell/command_s3_circuitbreaker_test.go
zooqueen dd74d3e6d6 Replace AGPL MinIO fork with Apache-2.0 SeaweedFS fork; rebrand CLI weed->s3
hanzoai/s3 was an AGPL-3.0 MinIO fork whose network-copyleft blocks embedding
and reselling as a managed service. Replace it wholesale with a fork of
SeaweedFS (github.com/seaweedfs/seaweedfs, Apache-2.0, Go) which ships a
built-in S3 gateway + Filer.

- License: AGPL-3.0 -> Apache-2.0 (upstream LICENSE kept verbatim, incl.
  "Copyright 2025 Chris Lu"); NOTICE added crediting SeaweedFS. No AGPL/BUSL/
  SSPL/GPL or enterprise ("ee") files remain.
- Module: go.mod path set to github.com/hanzoai/s3 with a self-replace
  (replace github.com/seaweedfs/seaweedfs => ./) so the ~1800 internal Go files
  keep their upstream import paths with zero churn. Internal identifiers and
  import paths are intentionally NOT renamed.
- CLI rebrand: the binary is built as `s3` (was `weed`); root usage, per-command
  help/usage/flag strings, shell autocomplete program name, and the product name
  in CLI output now read "Hanzo S3" / `s3`. Users never see `weed`.
  (e.g. `s3 server`, `s3 filer`, `s3 master`, `s3 volume`, `s3 s3`, `s3 mount`.)
- Build: `make` (or `go build -o s3 ./weed`) builds the `s3` binary green;
  `cmd/weed-db` and `cmd/weed-sql` also build; `go vet ./weed/command/` clean.
- README/LLM.md rewritten for Hanzo S3; AGENTS.md/CLAUDE.md symlinks preserved.
- Dropped a 33MB prebuilt Mach-O `stress` binary upstream had committed; `.gitignore`
  updated to ignore the `s3` build output.
2026-06-18 23:41:25 -07:00

293 lines
5.1 KiB
Go

package shell
import (
"bytes"
"encoding/json"
"reflect"
"strings"
"testing"
)
type Case struct {
args []string
result string
}
var (
TestCases = []*Case{
//add circuit breaker config for global
{
args: strings.Split("-global -type Count -actions Read,Write -values 500,200", " "),
result: `{
"global": {
"enabled": true,
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
}
}`,
},
//disable global config
{
args: strings.Split("-global -disable", " "),
result: `{
"global": {
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
}
}`,
},
//add circuit breaker config for buckets x,y,z
{
args: strings.Split("-buckets x,y,z -type Count -actions Read,Write -values 200,100", " "),
result: `{
"global": {
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
},
"buckets": {
"x": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"y": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
}
}
}`,
},
//disable circuit breaker config of x
{
args: strings.Split("-buckets x -disable", " "),
result: `{
"global": {
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
},
"buckets": {
"x": {
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"y": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
}
}
}`,
},
//delete circuit breaker config of x
{
args: strings.Split("-buckets x -delete", " "),
result: `{
"global": {
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
},
"buckets": {
"y": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
}
}
}`,
},
//configure the circuit breaker for the size of the uploaded file for bucket x,y
{
args: strings.Split("-buckets x,y -type MB -actions Write -values 1024", " "),
result: `{
"global": {
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
},
"buckets": {
"x": {
"enabled": true,
"actions": {
"Write:MB": "1073741824"
}
},
"y": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100",
"Write:MB": "1073741824"
}
},
"z": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
}
}
}`,
},
//delete the circuit breaker configuration for the size of the uploaded file of bucket x,y
{
args: strings.Split("-buckets x,y -type MB -actions Write -delete", " "),
result: `{
"global": {
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
},
"buckets": {
"x": {
"enabled": true
},
"y": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
}
}
}`,
},
//enable global circuit breaker config (without -disable flag)
{
args: strings.Split("-global", " "),
result: `{
"global": {
"enabled": true,
"actions": {
"Read:Count": "500",
"Write:Count": "200"
}
},
"buckets": {
"x": {
"enabled": true
},
"y": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
},
"z": {
"enabled": true,
"actions": {
"Read:Count": "200",
"Write:Count": "100"
}
}
}
}`,
},
//clear all circuit breaker config
{
args: strings.Split("-delete", " "),
result: `{
}`,
},
}
)
func TestCircuitBreakerShell(t *testing.T) {
var writeBuf bytes.Buffer
cmd := &commandS3CircuitBreaker{}
LoadConfig = func(commandEnv *CommandEnv, dir string, file string, buf *bytes.Buffer) error {
_, err := buf.Write(writeBuf.Bytes())
if err != nil {
return err
}
writeBuf.Reset()
return nil
}
for i, tc := range TestCases {
err := cmd.Do(tc.args, nil, &writeBuf)
if err != nil {
t.Fatal(err)
}
if i != 0 {
result := writeBuf.String()
actual := make(map[string]interface{})
err := json.Unmarshal([]byte(result), &actual)
if err != nil {
t.Error(err)
}
expect := make(map[string]interface{})
err = json.Unmarshal([]byte(result), &expect)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(actual, expect) {
t.Fatal("result of s3 circuit breaker shell command is unexpected!")
}
}
}
}