From 662c7e5ab9807f65cee3d5155904f7ee6cff1bc9 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoumand Date: Sat, 3 Feb 2024 14:06:43 +0330 Subject: [PATCH] feat: added is ok method for OSRM responses (#4) * chore: bump go version * ci: added go1.21 to the test pipeline * feat: added is ok method for OSRM responses --------- Co-authored-by: Mojtaba Arezoomand --- .github/workflows/test.yaml | 4 ++-- go.mod | 2 +- types.go | 5 +++++ types_test.go | 15 +++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 types_test.go diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 376ba72..702bbdc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ on: env: # Upload coverage only for this go version. - LATEST_GO_VERSION: "1.20" + LATEST_GO_VERSION: "1.21" jobs: test: @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest"] - go: ["1.18", "1.19", "1.20"] + go: ["1.18", "1.19", "1.20", "1.21"] name: ${{ matrix.os }} & Go ${{ matrix.go }} diff --git a/go.mod b/go.mod index 2a11642..5ef2a59 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mojixcoder/gosrm -go 1.20 +go 1.21 require github.com/stretchr/testify v1.8.2 diff --git a/types.go b/types.go index e1a3b9f..693c262 100644 --- a/types.go +++ b/types.go @@ -287,3 +287,8 @@ type ( Confidence float32 `json:"confidence"` } ) + +// IsOk returns true if request could be processed as expected by OSRM. +func (res Response) IsOk() bool { + return res.Code == CodeOK +} diff --git a/types_test.go b/types_test.go new file mode 100644 index 0000000..33b82eb --- /dev/null +++ b/types_test.go @@ -0,0 +1,15 @@ +package gosrm + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestResponse_IsOk(t *testing.T) { + res := Response{Code: CodeOK} + assert.True(t, res.IsOk()) + + res.Code = CodeInvalidQuery + assert.False(t, res.IsOk()) +}