@@ -20,7 +20,8 @@ limitations under the License.
20
20
package yaml
21
21
22
22
import (
23
- "bytes"
23
+ "fmt"
24
+ "strings"
24
25
25
26
"gopkg.in/yaml.v2"
26
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,8 +42,12 @@ func FuzzDurationStrict(b []byte) int {
41
42
if err != nil {
42
43
panic (err )
43
44
}
44
- if ! bytes .Equal (result , b ) {
45
- panic ("result != input" )
45
+ // Result is in the format "d: <duration>\n", so strip off the trailing
46
+ // newline and convert durationHolder.D to the expected format.
47
+ resultStr := strings .TrimSpace (string (result [:]))
48
+ inputStr := fmt .Sprintf ("d: %s" , durationHolder .D .Duration )
49
+ if resultStr != inputStr {
50
+ panic (fmt .Sprintf ("result(%v) != input(%v)" , resultStr , inputStr ))
46
51
}
47
52
return 1
48
53
}
@@ -61,8 +66,18 @@ func FuzzMicroTimeStrict(b []byte) int {
61
66
if err != nil {
62
67
panic (err )
63
68
}
64
- if ! bytes .Equal (result , b ) {
65
- panic ("result != input" )
69
+ // Result is in the format "t: <time>\n", so strip off the trailing
70
+ // newline and convert microTimeHolder.T to the expected format. If
71
+ // time is zero, the value is marshaled to "null".
72
+ resultStr := strings .TrimSpace (string (result [:]))
73
+ var inputStr string
74
+ if microTimeHolder .T .Time .IsZero () {
75
+ inputStr = "t: null"
76
+ } else {
77
+ inputStr = fmt .Sprintf ("t: %s" , microTimeHolder .T .Time )
78
+ }
79
+ if resultStr != inputStr {
80
+ panic (fmt .Sprintf ("result(%v) != input(%v)" , resultStr , inputStr ))
66
81
}
67
82
return 1
68
83
}
@@ -95,8 +110,18 @@ func FuzzTimeStrict(b []byte) int {
95
110
if err != nil {
96
111
panic (err )
97
112
}
98
- if ! bytes .Equal (result , b ) {
99
- panic ("result != input" )
113
+ // Result is in the format "t: <time>\n", so strip off the trailing
114
+ // newline and convert timeHolder.T to the expected format. If time is
115
+ // zero, the value is marshaled to "null".
116
+ resultStr := strings .TrimSpace (string (result [:]))
117
+ var inputStr string
118
+ if timeHolder .T .Time .IsZero () {
119
+ inputStr = "t: null"
120
+ } else {
121
+ inputStr = fmt .Sprintf ("t: %s" , timeHolder .T .Time )
122
+ }
123
+ if resultStr != inputStr {
124
+ panic (fmt .Sprintf ("result(%v) != input(%v)" , resultStr , inputStr ))
100
125
}
101
126
return 1
102
127
}
0 commit comments