File tree 3 files changed +66
-2
lines changed
3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -20,15 +20,23 @@ jobs:
20
20
strategy :
21
21
fail-fast : false
22
22
matrix :
23
+ golang :
24
+ - 1.13
23
25
tarantool :
24
26
- ' 1.10'
25
27
- ' 2.8'
26
28
- ' 2.9'
27
29
- ' 2.x-latest'
28
30
coveralls : [false]
31
+ fuzzing : [false]
29
32
include :
30
33
- tarantool : ' 2.x-latest'
31
34
coveralls : true
35
+ golang : 1.13
36
+ - tarantool : ' 2.x-latest'
37
+ fuzzing : true
38
+ golang : 1.18
39
+ coveralls : false
32
40
33
41
steps :
34
42
- name : Clone the connector
@@ -49,14 +57,18 @@ jobs:
49
57
- name : Setup golang for the connector and tests
50
58
uses : actions/setup-go@v2
51
59
with :
52
- go-version : 1.13
60
+ go-version : ${{ matrix.golang }}
53
61
54
62
- name : Install test dependencies
55
63
run : make deps
56
64
57
- - name : Run tests
65
+ - name : Run regression tests
58
66
run : make test
59
67
68
+ - name : Run fuzzing tests
69
+ if : ${{ matrix.fuzzing }}
70
+ run : make test-fuzzing
71
+
60
72
- name : Run tests, collect code coverage data and send to Coveralls
61
73
if : ${{ matrix.coveralls }}
62
74
env :
Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ test-decimal:
64
64
go clean -testcache
65
65
go test ./decimal/ -v -p 1
66
66
67
+ .PHONY : test-fuzzing
68
+ test-fuzzing :
69
+ @echo " Running fuzzing tests"
70
+ go clean -testcache
71
+ go test ./... -run=^Fuzz -v -p 1 -tags fuzzing
72
+
67
73
.PHONY : coverage
68
74
coverage :
69
75
go clean -testcache
Original file line number Diff line number Diff line change
1
+ //go:build fuzzing
2
+ // +build fuzzing
3
+
4
+ package decimal_test
5
+
6
+ import (
7
+ "testing"
8
+
9
+ "github.com/shopspring/decimal"
10
+ . "github.com/tarantool/go-tarantool/decimal"
11
+ )
12
+
13
+ func strToDecimal (t * testing.T , buf string ) decimal.Decimal {
14
+ decNum , err := decimal .NewFromString (buf )
15
+ if err != nil {
16
+ t .Fatal (err )
17
+ }
18
+ return decNum
19
+ }
20
+
21
+ func FuzzEncodeDecodeBCD (f * testing.F ) {
22
+ samples := append (correctnessSamples , benchmarkSamples ... )
23
+ for _ , testcase := range samples {
24
+ if len (testcase .numString ) > 0 {
25
+ f .Add (testcase .numString ) // Use f.Add to provide a seed corpus.
26
+ }
27
+ }
28
+ f .Fuzz (func (t * testing.T , orig string ) {
29
+ if l := GetNumberLength (orig ); l > DecimalPrecision {
30
+ t .Skip ("max number length is exceeded" )
31
+ }
32
+ bcdBuf , err := EncodeStringToBCD (orig )
33
+ if err != nil {
34
+ t .Skip ("Only correct requests are intresting: %w" , err )
35
+ }
36
+ var dec string
37
+ dec , err = DecodeStringFromBCD (bcdBuf )
38
+ if err != nil {
39
+ t .Fatalf ("Failed to decode encoded value ('%s')" , orig )
40
+ }
41
+
42
+ if ! strToDecimal (t , dec ).Equal (strToDecimal (t , orig )) {
43
+ t .Fatal ("Decimal numbers are not equal" )
44
+ }
45
+ })
46
+ }
You can’t perform that action at this time.
0 commit comments