diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d846055..e74d31a 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: @@ -7,16 +19,17 @@ 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 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 diff --git a/object/service.go b/object/service.go index b0afc55..e75c9f2 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 } diff --git a/object/service_test.go b/object/service_test.go new file mode 100644 index 0000000..f06e557 --- /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() }) + }) + } +}