Skip to content

Commit

Permalink
fix uripost test and go.mod
Browse files Browse the repository at this point in the history
fix uripost test and go.mod

Pull Request resolved: #161
  • Loading branch information
oke11o committed Jan 19, 2023
1 parent 867ac14 commit a2a64dc
Show file tree
Hide file tree
Showing 12 changed files with 557 additions and 135 deletions.
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"go.uber.org/zap/zapcore"
)

const Version = "0.5.2"
const Version = "0.5.3"
const defaultConfigFile = "load"
const stdinConfigSelector = "-"

Expand Down
2 changes: 1 addition & 1 deletion components/phttp/ammo/simple/raw/decoder_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ func BenchmarkRawDecoderWithHeaders(b *testing.B) {
b.StartTimer()
for i := 0; i < b.N; i++ {
req, _ := decodeRequest([]byte(benchTestRequest))
simple.UpdateRequestWithHeaders(req, decodedHTTPConfigHeaders)
simple.EnrichRequestWithHeaders(req, decodedHTTPConfigHeaders)
}
}
2 changes: 1 addition & 1 deletion components/phttp/ammo/simple/raw/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (p *Provider) start(ctx context.Context, ammoFile afero.File) error {
}

// add new Headers to request from config
simple.UpdateRequestWithHeaders(req, decodedConfigHeaders)
simple.EnrichRequestWithHeaders(req, decodedConfigHeaders)

sh := p.Pool.Get().(*simple.Ammo)
sh.Reset(req, tag)
Expand Down
2 changes: 1 addition & 1 deletion components/phttp/ammo/simple/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func DecodeHTTPConfigHeaders(headers []string) (configHTTPHeaders []Header, err
return
}

func UpdateRequestWithHeaders(req *http.Request, headers []Header) {
func EnrichRequestWithHeaders(req *http.Request, headers []Header) {
origHeaders := req.Header.Clone()
for _, header := range headers {
if origHeaders.Get(header.key) != "" {
Expand Down
47 changes: 47 additions & 0 deletions components/phttp/ammo/simple/request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package simple

import (
"net/http"
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("HTTPHeaders", func() {
It("decode http config headers", func() {
decodedConfigHeaders, err := DecodeHTTPConfigHeaders([]string{
"[Host: youhost.tld]",
"[SomeHeader: somevalue]",
})
expectHeaders := []Header{
{"Host", "youhost.tld"},
{"SomeHeader", "somevalue"},
}
Expect(err).To(BeNil())
Expect(decodedConfigHeaders).To(Equal(expectHeaders))
})

It("add new http headers", func() {
const origHost = "example.com"
req, _ := http.NewRequest("GET", origHost, nil)
req.Host = origHost
req.Header.Set("SomeHeader", "oldvalue")
headers := []Header{
{"Host", "youhost.tld"},
{"SomeHeader", "newvalue"},
{"SecondHeader", "new_second_value"},
}
EnrichRequestWithHeaders(req, headers)
Expect(req.Host).To(Equal(origHost))
Expect(req.Header).To(Equal(http.Header{
"Someheader": []string{"oldvalue"},
"Secondheader": []string{"new_second_value"},
}))
})
})

func TestExample(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Example Suite")
}
2 changes: 1 addition & 1 deletion components/phttp/ammo/simple/uri/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *decoder) decodeURI(line []byte) error {
}

// add new Headers to request from config
simple.UpdateRequestWithHeaders(req, d.configHeaders)
simple.EnrichRequestWithHeaders(req, d.configHeaders)

sh := d.pool.Get().(*simple.Ammo)
sh.Reset(req, tag)
Expand Down
15 changes: 0 additions & 15 deletions components/phttp/ammo/simple/uripost/decoder_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uripost

import (
"reflect"
"strconv"
"testing"
)
Expand Down Expand Up @@ -78,17 +77,3 @@ func TestDecodeBadURI(t *testing.T) {
}

}

func TestDecodeHTTPConfigHeaders(t *testing.T) {
headers := []string{
"[Host: some.host]",
"[User-Agent: Tank]",
}

header := []Header{{key: "Host", value: "some.host"}, {key: "User-Agent", value: "Tank"}}
configHeaders, err := decodeHTTPConfigHeaders(headers)
if err == nil && !reflect.DeepEqual(configHeaders, header) {
t.Errorf("Got: %v, expected: %v", configHeaders, header)
}

}
2 changes: 1 addition & 1 deletion components/phttp/ammo/simple/uripost/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (p *Provider) start(ctx context.Context, ammoFile afero.File) error {
}

// add new Headers to request from config
simple.UpdateRequestWithHeaders(req, decodedConfigHeaders)
simple.EnrichRequestWithHeaders(req, decodedConfigHeaders)

sh := p.Pool.Get().(*simple.Ammo)
sh.Reset(req, tag)
Expand Down
4 changes: 2 additions & 2 deletions core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestMapRecursive(t *testing.T) {
}
n := &N{MultiStrings: MultiStrings{B: "b"}, A: "a"}
Map(n, &M{MultiStrings: MultiStrings{A: "a"}})
assert.Equal(t, &N{A: "a", MultiStrings: MultiStrings{A: "a"}}, n)
assert.Equal(t, &N{A: "a", MultiStrings: MultiStrings{A: "a", B: ""}}, n)
}

func TestMapTagged(t *testing.T) {
Expand All @@ -184,7 +184,7 @@ func TestMapTagged(t *testing.T) {
}
n := &N{MultiStrings: MultiStrings{B: "b"}, A: "a"}
Map(n, &M{SomeOtherFieldName: MultiStrings{A: "a"}})
assert.Equal(t, &N{A: "a", MultiStrings: MultiStrings{A: "a"}}, n)
assert.Equal(t, &N{A: "a", MultiStrings: MultiStrings{A: "a", B: ""}}, n)
}
func TestDeltaUpdate(t *testing.T) {
var l2 Level2
Expand Down
1 change: 1 addition & 0 deletions core/engine/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var _ = Describe("Instance", func() {
sched.On("Left").Return(1)
gun.On("Bind", aggregator, mock.Anything).Return(nil)
provider.On("Acquire").Return(struct{}{}, true)
provider.On("Release", mock.Anything).Return()
})
It("start fail", func() {
err := ins.Run(ctx)
Expand Down
84 changes: 48 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
module github.com/yandex/pandora

go 1.17
go 1.19

require (
github.com/asaskevich/govalidator v0.0.0-20171111151018-521b25f4b05f
github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052
github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4
github.com/ghodss/yaml v1.0.0
github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874
github.com/hashicorp/go-multierror v1.1.1
github.com/jhump/protoreflect v1.10.1
github.com/json-iterator/go v0.0.0-20180214060632-e7c7f3b33712
github.com/mitchellh/mapstructure v0.0.0-20180203102830-a4e142e9c047
github.com/onsi/ginkgo v1.4.0
github.com/onsi/gomega v1.3.0
github.com/pkg/errors v0.9.0
github.com/pquerna/ffjson v0.0.0-20171002144729-d49c2bc1aa13
github.com/spf13/afero v1.0.2
github.com/spf13/viper v1.0.0
github.com/stretchr/testify v1.7.0
go.uber.org/atomic v1.3.1
go.uber.org/zap v1.7.1
golang.org/x/net v0.0.0-20200822124328-c89045814202
google.golang.org/grpc v1.41.0
github.com/json-iterator/go v1.1.12
github.com/mitchellh/mapstructure v1.5.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.20.1
github.com/pkg/errors v0.9.1
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7
github.com/spf13/afero v1.9.2
github.com/spf13/viper v1.13.0
github.com/stretchr/testify v1.8.1
go.uber.org/atomic v1.10.0
go.uber.org/zap v1.23.0
golang.org/x/net v0.3.0
google.golang.org/grpc v1.50.1
gopkg.in/bluesuncorp/validator.v9 v9.10.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-playground/locales v0.11.2 // indirect
github.com/go-playground/universal-translator v0.16.0 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/pelletier/go-toml v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo/v2 v2.1.6 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cast v1.2.0 // indirect
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec // indirect
github.com/spf13/pflag v1.0.0 // indirect
github.com/stretchr/objx v0.1.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 // indirect
golang.org/x/text v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/yaml.v2 v2.2.3 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
go.uber.org/goleak v1.2.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20220930163606-c98284e70a91 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit a2a64dc

Please sign in to comment.