From f52156e76cf02e0b3de993fa6d9ba0d2f4e52001 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 25 Dec 2020 00:55:15 +0300 Subject: Initial commit of experiment --- tests/plugins/http/parse_test.go | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/plugins/http/parse_test.go (limited to 'tests/plugins/http/parse_test.go') diff --git a/tests/plugins/http/parse_test.go b/tests/plugins/http/parse_test.go new file mode 100644 index 00000000..5cc1ce32 --- /dev/null +++ b/tests/plugins/http/parse_test.go @@ -0,0 +1,54 @@ +package http + +import ( + "testing" + + "github.com/spiral/roadrunner/v2/plugins/http" +) + +var samples = []struct { + in string + out []string +}{ + {"key", []string{"key"}}, + {"key[subkey]", []string{"key", "subkey"}}, + {"key[subkey]value", []string{"key", "subkey", "value"}}, + {"key[subkey][value]", []string{"key", "subkey", "value"}}, + {"key[subkey][value][]", []string{"key", "subkey", "value", ""}}, + {"key[subkey] [value][]", []string{"key", "subkey", "value", ""}}, + {"key [ subkey ] [ value ] [ ]", []string{"key", "subkey", "value", ""}}, +} + +func Test_FetchIndexes(t *testing.T) { + for i := 0; i < len(samples); i++ { + r := http.FetchIndexes(samples[i].in) + if !same(r, samples[i].out) { + t.Errorf("got %q, want %q", r, samples[i].out) + } + } +} + +func BenchmarkConfig_FetchIndexes(b *testing.B) { + for _, tt := range samples { + for n := 0; n < b.N; n++ { + r := http.FetchIndexes(tt.in) + if !same(r, tt.out) { + b.Fail() + } + } + } +} + +func same(in, out []string) bool { + if len(in) != len(out) { + return false + } + + for i, v := range in { + if v != out[i] { + return false + } + } + + return true +} -- cgit v1.2.3 From 8526c03822e724bc2ebb64b6197085fea335b782 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 25 Dec 2020 14:46:01 +0300 Subject: Move root plugins to the pkg --- tests/plugins/http/parse_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/plugins/http/parse_test.go') diff --git a/tests/plugins/http/parse_test.go b/tests/plugins/http/parse_test.go index 5cc1ce32..df217202 100644 --- a/tests/plugins/http/parse_test.go +++ b/tests/plugins/http/parse_test.go @@ -3,7 +3,7 @@ package http import ( "testing" - "github.com/spiral/roadrunner/v2/plugins/http" + "github.com/spiral/roadrunner/v2/pkg/plugins/http" ) var samples = []struct { -- cgit v1.2.3 From 7a0dee1a416705c621edbf50e1f43fb39845348f Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Sat, 26 Dec 2020 00:40:31 +0300 Subject: Huge tests refactoring. Reduce running time 2-3x times --- tests/plugins/http/parse_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/plugins/http/parse_test.go') diff --git a/tests/plugins/http/parse_test.go b/tests/plugins/http/parse_test.go index df217202..5cc1ce32 100644 --- a/tests/plugins/http/parse_test.go +++ b/tests/plugins/http/parse_test.go @@ -3,7 +3,7 @@ package http import ( "testing" - "github.com/spiral/roadrunner/v2/pkg/plugins/http" + "github.com/spiral/roadrunner/v2/plugins/http" ) var samples = []struct { -- cgit v1.2.3