File tree 3 files changed +69
-2
lines changed
3 files changed +69
-2
lines changed Original file line number Diff line number Diff line change @@ -26,12 +26,23 @@ jobs:
26
26
strategy :
27
27
fail-fast : false
28
28
matrix :
29
+ golang :
30
+ - 1.13
29
31
tarantool :
30
32
- ' 1.10'
31
33
- ' 2.8'
32
34
- ' 2.9'
33
35
- ' 2.x-latest'
34
36
coveralls : [false]
37
+ fuzzing : [false]
38
+ include :
39
+ - tarantool : ' 2.x-latest'
40
+ coveralls : true
41
+ golang : 1.13
42
+ - tarantool : ' 2.x-latest'
43
+ fuzzing : true
44
+ golang : 1.18
45
+ coveralls : false
35
46
36
47
steps :
37
48
- name : Clone the connector
@@ -52,14 +63,18 @@ jobs:
52
63
- name : Setup golang for the connector and tests
53
64
uses : actions/setup-go@v2
54
65
with :
55
- go-version : 1.13
66
+ go-version : ${{ matrix.golang }}
56
67
57
68
- name : Install test dependencies
58
69
run : make deps
59
70
60
- - name : Run tests
71
+ - name : Run regression tests
61
72
run : make test
62
73
74
+ - name : Run fuzzing tests
75
+ if : ${{ matrix.fuzzing }}
76
+ run : make test-fuzzing
77
+
63
78
- name : Run tests, collect code coverage data and send to Coveralls
64
79
if : ${{ matrix.coveralls }}
65
80
env :
Original file line number Diff line number Diff line change @@ -76,6 +76,12 @@ test-decimal:
76
76
go clean -testcache
77
77
go test ./decimal/ -v -p 1
78
78
79
+ .PHONY : test-fuzzing
80
+ test-fuzzing :
81
+ @echo " Running fuzzing tests"
82
+ go clean -testcache
83
+ go test ./... -run=^Fuzz -v -p 1 -tags fuzzing
84
+
79
85
.PHONY : coverage
80
86
coverage :
81
87
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 interesting: %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