Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 18 additions & 5 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,32 @@ jobs:
strategy:
matrix:
go-version:
- '1.18' # oldest supported; named in go.mod
- '1.23' # named in go.mod
- 'oldstable'
- 'stable'
env:
TEST_RESULTS: "/tmp/test-results"
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
- name: Checkout Code
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Setup go
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Run golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5
- uses: autero1/action-gotestsum@7263b9d73912eec65f46337689e59fac865c425f # v2.0.0
with:
gotestsum_version: 1.9.0

- run: make test
- name: Run test
run: make test
- name: Unit test coverage
run: make coverage
- name: Upload coverage report
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
path: /tmp/coverage.out
name: Coverage-report-${{ matrix.go-version }}
- name: Display coverage report
run: go tool cover -func=/tmp/coverage.out
1 change: 1 addition & 0 deletions .go-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.23
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters:
enable:
- errcheck
output_format: colored-line-number
18 changes: 0 additions & 18 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package bexpr

import (
"flag"
"reflect"
)

var benchFull *bool = flag.Bool("bench-full", false, "Run all benchmarks rather than a subset")
Expand Down Expand Up @@ -71,23 +70,6 @@ type testFlatStructAlt struct {
Hidden CustomBool `bexpr:"-"`
}

var testFlatStructKindMap map[string]reflect.Kind = map[string]reflect.Kind{
"Int": reflect.Int,
"Int8": reflect.Int8,
"Int16": reflect.Int16,
"Int32": reflect.Int32,
"Int64": reflect.Int64,
"Uint": reflect.Uint,
"Uint8": reflect.Uint8,
"Uint16": reflect.Uint16,
"Uint32": reflect.Uint32,
"Uint64": reflect.Uint64,
"Float32": reflect.Float32,
"Float64": reflect.Float64,
"Bool": reflect.Bool,
"String": reflect.String,
}

type testNestedLevel2_1 struct {
Foo int
bar string
Expand Down
38 changes: 23 additions & 15 deletions evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,22 @@ var evaluateTests map[string]expressionTest = map[string]expressionTest{
},
"Flat Struct Alt Types": {
testFlatStructAlt{
Int: -1,
Int8: -2,
Int16: -3,
Int32: -4,
Int64: -5,
Uint: 6,
Uint8: 7,
Uint16: 8,
Uint32: 9,
Uint64: 10,
Float32: 1.1,
Float64: 1.2,
Bool: true,
String: "exported",
Hidden: true,
Int: -1,
Int8: -2,
Int16: -3,
Int32: -4,
Int64: -5,
Uint: 6,
Uint8: 7,
Uint16: 8,
Uint32: 9,
Uint64: 10,
Float32: 1.1,
Float64: 1.2,
Bool: true,
String: "exported",
unexported: "unexported",
Hidden: true,
},
[]expressionCheck{
{expression: "Int == -1", result: true, benchQuick: true},
Expand Down Expand Up @@ -255,10 +256,12 @@ var evaluateTests map[string]expressionTest = map[string]expressionTest{
MapOfStructs: map[string]testNestedLevel2_1{
"one": {
Foo: 42,
bar: "unexported",
Baz: "exported",
},
"two": {
Foo: 77,
bar: "unexported",
Baz: "consul",
},
},
Expand Down Expand Up @@ -300,6 +303,11 @@ var evaluateTests map[string]expressionTest = map[string]expressionTest{
{expression: "TopInt != 0", result: true},
{expression: "Nested.Map contains nope or (Nested.Map contains bar and Nested.Map.bar == `bazel`) or TopInt != 0", result: true, benchQuick: true},
{expression: "Nested.MapOfStructs.one.Foo == 42", result: true},
{expression: "Nested.MapOfStructs.one.bar == `unexported`", result: false, err: `error finding value in datum: /Nested/MapOfStructs/one/bar at part 3: couldn't find key: struct field with name "bar"`},
{expression: "Nested.MapOfStructs.one.Baz == `exported`", result: true},
{expression: "Nested.MapOfStructs.two.Foo == 77", result: true},
{expression: "Nested.MapOfStructs.two.bar == `unexported`", result: false, err: `error finding value in datum: /Nested/MapOfStructs/two/bar at part 3: couldn't find key: struct field with name "bar"`},
{expression: "Nested.MapOfStructs.two.Baz == `consul`", result: true},
{expression: "7 in Nested.SliceOfInts", result: true},
{expression: `"/Nested/SliceOfInts" == "7"`, result: false, err: `unable to find suitable primitive comparison function for matching`},
{expression: "Nested.MapOfStructs is empty or (Nested.SliceOfInts contains 7 and 9 in Nested.SliceOfInts)", result: true, benchQuick: true},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/hashicorp/go-bexpr

go 1.18
go 1.23

require (
github.com/mitchellh/pointerstructure v1.2.1
Expand Down