aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_s3_circuitbreaker_test.go
diff options
context:
space:
mode:
author石昌林 <changlin.shi@ly.com>2022-06-17 19:07:39 +0800
committer石昌林 <changlin.shi@ly.com>2022-06-17 19:07:39 +0800
commit3dd60529c517d6cabfb5ff513013680678d8d3ff (patch)
treee8a7c4f28663a9487f9510147983a871163592d2 /weed/shell/command_s3_circuitbreaker_test.go
parent37df209195995d619fe2fc9ae7b9798cd745e55d (diff)
downloadseaweedfs-3dd60529c517d6cabfb5ff513013680678d8d3ff.tar.xz
seaweedfs-3dd60529c517d6cabfb5ff513013680678d8d3ff.zip
some code optimizations
Diffstat (limited to 'weed/shell/command_s3_circuitbreaker_test.go')
-rw-r--r--weed/shell/command_s3_circuitbreaker_test.go145
1 files changed, 131 insertions, 14 deletions
diff --git a/weed/shell/command_s3_circuitbreaker_test.go b/weed/shell/command_s3_circuitbreaker_test.go
index 214256b5c..191a62e6a 100644
--- a/weed/shell/command_s3_circuitbreaker_test.go
+++ b/weed/shell/command_s3_circuitbreaker_test.go
@@ -2,6 +2,8 @@ package shell
import (
"bytes"
+ "encoding/json"
+ "reflect"
"strings"
"testing"
)
@@ -15,33 +17,137 @@ var (
TestCases = []*Case{
//add circuit breaker config for global
{
- args: strings.Split("-global -type count -actions Read,Write -values 500,200", " "),
- result: "{\n \"global\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"500\",\n \"Write:count\": \"200\"\n }\n }\n}\n",
+ 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: "{\n \"global\": {\n \"actions\": {\n \"Read:count\": \"500\",\n \"Write:count\": \"200\"\n }\n }\n}\n",
+ 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: "{\n \"global\": {\n \"actions\": {\n \"Read:count\": \"500\",\n \"Write:count\": \"200\"\n }\n },\n \"buckets\": {\n \"x\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n },\n \"y\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n },\n \"z\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n }\n }\n}\n",
+ 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: "{\n \"global\": {\n \"actions\": {\n \"Read:count\": \"500\",\n \"Write:count\": \"200\"\n }\n },\n \"buckets\": {\n \"x\": {\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n },\n \"y\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n },\n \"z\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n }\n }\n}\n",
+ 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: "{\n \"global\": {\n \"actions\": {\n \"Read:count\": \"500\",\n \"Write:count\": \"200\"\n }\n },\n \"buckets\": {\n \"y\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n },\n \"z\": {\n \"enabled\": true,\n \"actions\": {\n \"Read:count\": \"200\",\n \"Write:count\": \"100\"\n }\n }\n }\n}\n",
+ 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"
+ }
+ }
+ }
+ }`,
},
+
//clear all circuit breaker config
{
- args: strings.Split("-delete", " "),
- result: "{\n\n}\n",
+ args: strings.Split("-delete", " "),
+ result: `{
+
+ }`,
},
}
)
@@ -65,10 +171,21 @@ func TestCircuitBreakerShell(t *testing.T) {
}
if i != 0 {
result := writeBuf.String()
- if result != tc.result {
- t.Fatal("result of s3 circuit breaker shell command is unexpect!")
+
+ 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 unexpect!")
+ }
}
}
}