diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index 1317244..ea6d6c1 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -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 \ No newline at end of file diff --git a/.go-version b/.go-version new file mode 100644 index 0000000..193d140 --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.23 \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..8467b99 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,4 @@ +linters: + enable: + - errcheck +output_format: colored-line-number \ No newline at end of file diff --git a/common_test.go b/common_test.go index 00fbc0c..58079bd 100644 --- a/common_test.go +++ b/common_test.go @@ -5,7 +5,6 @@ package bexpr import ( "flag" - "reflect" ) var benchFull *bool = flag.Bool("bench-full", false, "Run all benchmarks rather than a subset") @@ -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 diff --git a/evaluate_test.go b/evaluate_test.go index 138ad38..1d52ab3 100644 --- a/evaluate_test.go +++ b/evaluate_test.go @@ -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}, @@ -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", }, }, @@ -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}, diff --git a/go.mod b/go.mod index fed408d..46e827a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/go-bexpr -go 1.18 +go 1.23 require ( github.com/mitchellh/pointerstructure v1.2.1