Skip to content

error handling w/o error slices and more #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c6f0308
initial error handling refactoring
jxsl13 Aug 19, 2023
1cc2a40
fix some tests
jxsl13 Aug 19, 2023
bd65eb9
use filter func that is initialized only once
jxsl13 Aug 19, 2023
82f80e3
return broken object upon error as expected in the tests
jxsl13 Aug 20, 2023
a3eb526
fix example
jxsl13 Aug 20, 2023
8bc8538
update lower level tests
jxsl13 Aug 20, 2023
23ca2ac
do not return objects with errors
jxsl13 Aug 20, 2023
f64b868
fix tests, revert to returning objects even tho we have errors (circu…
jxsl13 Aug 20, 2023
18902b9
update ci go version to match go.mod version
jxsl13 Aug 20, 2023
b11b31a
harden ci pipeline
jxsl13 Aug 20, 2023
beed338
add dependabot
jxsl13 Aug 20, 2023
6b2595b
go fmt ./...
jxsl13 Aug 20, 2023
1a740b7
fix some linter warnings
jxsl13 Aug 20, 2023
1d14787
remove redundant break statements
jxsl13 Aug 20, 2023
f0d8af0
compile regex only once
jxsl13 Aug 20, 2023
2af5be8
use copy intead of for loop
jxsl13 Aug 20, 2023
3e55a41
fix some linter warnings
jxsl13 Aug 20, 2023
987651d
fix some linter warnings
jxsl13 Aug 20, 2023
06876cb
compile regex only once
jxsl13 Aug 20, 2023
5438afe
trim suffix with stdlib
jxsl13 Aug 20, 2023
127b681
update test
jxsl13 Aug 20, 2023
ecf7db3
allow reference resolving by default
jxsl13 Aug 20, 2023
745af79
update test to accomodate the default value change
jxsl13 Aug 20, 2023
38d5c31
fix example
jxsl13 Aug 20, 2023
d8abbdb
update MultiError
jxsl13 Aug 20, 2023
d9b4b37
try to keep MultiError flat
jxsl13 Aug 20, 2023
c48b1bd
remove unused error mapper functions
jxsl13 Aug 20, 2023
c4fcda1
decrease error handling complexity
jxsl13 Aug 20, 2023
4381bee
add errorutils tests
jxsl13 Aug 20, 2023
9da55d5
make zero value config struct the same as the default config
jxsl13 Aug 20, 2023
c3aa80c
test splitting test, race & coverage
jxsl13 Aug 26, 2023
e73fc93
Merge branch 'main' into poc/error-handling
jxsl13 Aug 26, 2023
b434c89
update go.sum
jxsl13 Aug 26, 2023
8c2c821
try w/o timeout
jxsl13 Aug 26, 2023
f6735fe
add makefile with the complete test commands
jxsl13 Aug 26, 2023
63207d2
add t.Parallel to tests that don't have global shared stats
jxsl13 Aug 26, 2023
9ec2200
rm -race flag
jxsl13 Aug 30, 2023
af5bb0d
Merge branch 'main' into poc/error-handling
jxsl13 Sep 1, 2023
6381834
fix build.yaml
jxsl13 Sep 1, 2023
04407cc
fix multiple calls to t.Parallel()
jxsl13 Sep 1, 2023
e834c01
and filter logic -> or filter logic
jxsl13 Sep 1, 2023
d2a8bc8
improve configuration & add tests
jxsl13 Sep 1, 2023
b842c44
improve filter & make tests more understandable
jxsl13 Sep 1, 2023
c9cb487
call all option functions for more test coverage
jxsl13 Sep 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
reviewers:
- "daveshanley"

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
reviewers:
- "daveshanley"
103 changes: 69 additions & 34 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,84 @@
name: Build
name: Build & Test

on:
push:
branches:
- main
branches: [ "main" ]
paths:
- '**.go'
- '**.yaml'
- '**.yml'
- '**.toml'
- '**.json'
- 'go.mod'
- 'go.sum'
pull_request:
branches:
- main
# The branches below must be a subset of the branches above
branches: [ "main" ]
paths:
- '**.go'
- '**.yaml'
- '**.yml'
- '**.toml'
- '**.json'
- 'go.mod'
- 'go.sum'

jobs:
build:
name: Build
runs-on: ubuntu-latest
name: Build & Test
strategy:
matrix:
go-version: ['stable', 'oldstable']
platform: ['ubuntu-latest']
runs-on: ${{ matrix.platform }}
permissions:
# required for security related workflows
security-events: write
# only required for workflows in private repositories
actions: read
contents: read
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.19
id: go

- name: Checkout code
uses: actions/checkout@v3

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Test
run: go test ./...
- name: Coverage
run: |
go get github.com/axw/gocov/gocov
go get github.com/AlekSi/gocov-xml
go install github.com/axw/gocov/gocov
go install github.com/AlekSi/gocov-xml
- run: |
go test -v -coverprofile cover.out ./...
gocov convert cover.out | gocov-xml > coverage.xml
- uses: codecov/codecov-action@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Vet
run: go vet ./...

- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest

- name: Run govulncheck
run: govulncheck ./...

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: '-no-fail -fmt sarif -out results.sarif ./...'
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
# Path to SARIF file relative to the root of the repository
sarif_file: results.sarif


- name: Test & Code Coverage
# https://go.dev/blog/cover
# -covermode=set (if a statement was run = default)
# -covermode=count (how many times a statement was run)
# -covermode=atomic (how many times a statement was run, even in parallel)
run: go test -v -coverprofile=coverage.out ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
files: ./coverage.out
fail_ci_if_error: false
verbose: true

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
test-operation.yaml
.idea/
*.iml
*.iml
__debug_bin*
coverage.out
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

build:
go build ./...

test:
go test -v -timeout 30m -count=1 ./...

race:
go test -v -timeout 30m -count=1 -race ./...

coverage:
go test -v -timeout 30m -count=1 -covermode=atomic -coverprofile=coverage.out ./...
5 changes: 4 additions & 1 deletion datamodel/document_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
package datamodel

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewClosedDocumentConfiguration(t *testing.T) {
t.Parallel()
cfg := NewClosedDocumentConfiguration()
assert.False(t, cfg.AllowRemoteReferences)
assert.False(t, cfg.AllowFileReferences)
}

func TestNewOpenDocumentConfiguration(t *testing.T) {
t.Parallel()
cfg := NewOpenDocumentConfiguration()
assert.True(t, cfg.AllowRemoteReferences)
assert.True(t, cfg.AllowFileReferences)
Expand Down
7 changes: 4 additions & 3 deletions datamodel/high/base/contact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ package base

import (
"fmt"
"testing"

lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)

func TestNewContact(t *testing.T) {

t.Parallel()
var cNode yaml.Node

yml := `name: pizza
Expand Down Expand Up @@ -58,7 +59,7 @@ email: [email protected]`
}

func TestContact_MarshalYAML(t *testing.T) {

t.Parallel()
yml := `name: Buckaroo
url: https://pb33f.io
email: [email protected]
Expand Down
7 changes: 4 additions & 3 deletions datamodel/high/base/discriminator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ package base

import (
"fmt"
"strings"
"testing"

lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"strings"
"testing"
)

func TestNewDiscriminator(t *testing.T) {

t.Parallel()
var cNode yaml.Node

yml := `propertyName: coffee
Expand Down
21 changes: 15 additions & 6 deletions datamodel/high/base/dynamic_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,67 @@
package base

import (
"strings"
"testing"

"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/pb33f/libopenapi/index"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"strings"
"testing"
)

func TestDynamicValue_Render_A(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, int]{N: 0, A: "hello"}
dvb, _ := dv.Render()
assert.Equal(t, "hello", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_B(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, int]{N: 1, B: 12345}
dvb, _ := dv.Render()
assert.Equal(t, "12345", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_Bool(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, bool]{N: 1, B: true}
dvb, _ := dv.Render()
assert.Equal(t, "true", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_Int64(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, int64]{N: 1, B: 12345567810}
dvb, _ := dv.Render()
assert.Equal(t, "12345567810", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_Int32(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, int32]{N: 1, B: 1234567891}
dvb, _ := dv.Render()
assert.Equal(t, "1234567891", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_Float32(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, float32]{N: 1, B: 23456.123}
dvb, _ := dv.Render()
assert.Equal(t, "23456.123", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_Float64(t *testing.T) {
t.Parallel()
dv := &DynamicValue[string, float64]{N: 1, B: 23456.1233456778}
dvb, _ := dv.Render()
assert.Equal(t, "23456.1233456778", strings.TrimSpace(string(dvb)))
}

func TestDynamicValue_Render_Ptr(t *testing.T) {
t.Parallel()

type cake struct {
Cake string
Expand All @@ -67,7 +76,7 @@ func TestDynamicValue_Render_Ptr(t *testing.T) {
}

func TestDynamicValue_Render_PtrRenderable(t *testing.T) {

t.Parallel()
tag := &Tag{
Name: "cake",
}
Expand All @@ -78,7 +87,7 @@ func TestDynamicValue_Render_PtrRenderable(t *testing.T) {
}

func TestDynamicValue_RenderInline(t *testing.T) {

t.Parallel()
tag := &Tag{
Name: "cake",
}
Expand All @@ -89,7 +98,7 @@ func TestDynamicValue_RenderInline(t *testing.T) {
}

func TestDynamicValue_MarshalYAMLInline(t *testing.T) {

t.Parallel()
const ymlComponents = `components:
schemas:
rice:
Expand Down Expand Up @@ -133,7 +142,7 @@ func TestDynamicValue_MarshalYAMLInline(t *testing.T) {
}

func TestDynamicValue_MarshalYAMLInline_Error(t *testing.T) {

t.Parallel()
const ymlComponents = `components:
schemas:
rice:
Expand Down
8 changes: 5 additions & 3 deletions datamodel/high/base/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ package base

import (
"fmt"
"strings"
"testing"

lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"strings"
"testing"
)

func TestNewExample(t *testing.T) {

t.Parallel()
var cNode yaml.Node

yml := `summary: an example
Expand Down Expand Up @@ -49,6 +50,7 @@ x-hack: code`
}

func TestExtractExamples(t *testing.T) {
t.Parallel()
var cNode yaml.Node

yml := `summary: herbs`
Expand Down
7 changes: 4 additions & 3 deletions datamodel/high/base/external_doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ package base

import (
"fmt"
"strings"
"testing"

lowmodel "github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"strings"
"testing"
)

func TestNewExternalDoc(t *testing.T) {

t.Parallel()
var cNode yaml.Node

yml := `description: hack code
Expand Down
Loading