From eab0a26cc07fc675fa01bec1ea0fdd1a0d37c6d3 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 16 Mar 2020 18:34:13 +0300 Subject: [PATCH 1/5] [NPE] check that header exists, otherwise return empty string --- object/service.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/object/service.go b/object/service.go index b0afc551..e75c9f25 100644 --- a/object/service.go +++ b/object/service.go @@ -124,7 +124,12 @@ func (m *GetResponse) NotFull() bool { return checkIsNotFull(m) } func (m *PutRequest) NotFull() bool { return checkIsNotFull(m) } // CID returns container id value from object put request. -func (m *PutRequest) CID() CID { return m.GetHeader().Object.SystemHeader.CID } +func (m *PutRequest) CID() CID { + if header := m.GetHeader(); header != nil { + return header.Object.SystemHeader.CID + } + return refs.CID{} +} // CID returns container id value from object get request. func (m *GetRequest) CID() CID { return m.Address.CID } From ea0703e089f5df26b0b489f4e2335d0e9a2ad3a3 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 16 Mar 2020 18:34:56 +0300 Subject: [PATCH 2/5] add tests case to prevent npe --- object/service_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 object/service_test.go diff --git a/object/service_test.go b/object/service_test.go new file mode 100644 index 00000000..f06e557e --- /dev/null +++ b/object/service_test.go @@ -0,0 +1,28 @@ +package object + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestRequest(t *testing.T) { + cases := []Request{ + &PutRequest{}, + &GetRequest{}, + &HeadRequest{}, + &SearchRequest{}, + &DeleteRequest{}, + &GetRangeRequest{}, + &GetRangeHashRequest{}, + } + + for i := range cases { + v := cases[i] + + t.Run(fmt.Sprintf("%T", v), func(t *testing.T) { + require.NotPanics(t, func() { v.CID() }) + }) + } +} From 164897604764d2f6ac75d2b0e7adc4549643cf54 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 16 Mar 2020 18:37:57 +0300 Subject: [PATCH 3/5] drop go 1.11 from tests --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d8460559..77b6a5e0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.11.x', '1.12.x', '1.13.x'] + go: [ '1.12.x', '1.13.x', '1.14.x'] steps: - name: Setup go From 5a63112f5356b4f5de2bc7d59c761dedb26bc15f Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 16 Mar 2020 18:43:48 +0300 Subject: [PATCH 4/5] ci cache modules --- .github/workflows/go.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 77b6a5e0..e74d31aa 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,17 @@ name: Go -on: [push] +on: + push: + branches: + - master + - develop + paths-ignore: + - '*.md' + pull_request: + branches: + - master + - develop + paths-ignore: + - '*.md' jobs: test: @@ -14,9 +26,10 @@ jobs: uses: actions/setup-go@v1 with: go-version: ${{ matrix.go }} + id: go - name: Check out code into the Go module directory - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Set GOPATH # temporary fix @@ -26,6 +39,13 @@ jobs: echo "##[add-path]$(dirname $GITHUB_WORKSPACE)/bin" shell: bash + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Get dependencies run: | go get -u -v golang.org/x/lint/golint From f3d0f43eb3107e03d1eaa0f793137f9a6a27a42a Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Mon, 16 Mar 2020 18:58:27 +0300 Subject: [PATCH 5/5] CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de5255e9..f2717079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog This is the changelog for NeoFS API +## [0.4.2] - 2020-03-16 + +### Fixed +- NPE bug with CID method of object.PutRequest + ## [0.4.1] - 2020-03-02 ### Changed @@ -204,3 +209,4 @@ Initial public release [0.3.2]: https://github.com/nspcc-dev/neofs-api/compare/v0.3.1...v0.3.2 [0.4.0]: https://github.com/nspcc-dev/neofs-api/compare/v0.3.2...v0.4.0 [0.4.1]: https://github.com/nspcc-dev/neofs-api/compare/v0.4.0...v0.4.1 +[0.4.2]: https://github.com/nspcc-dev/neofs-api/compare/v0.4.1...v0.4.2