11package options
22
33import (
4- "reflect"
54 "testing"
65 "time"
6+
7+ "github.com/stretchr/testify/require"
78)
89
910func TestTimeToLiveSettingsFluentModifiers (t * testing.T ) {
@@ -16,7 +17,49 @@ func TestTimeToLiveSettingsFluentModifiers(t *testing.T) {
1617 WithColumnName ("a" ).
1718 WithColumnUnit (TimeToLiveUnitSeconds ).
1819 WithMode (TimeToLiveModeValueSinceUnixEpoch ).
19- WithExpireAfter (time .Hour ),
20+ ExpireAfter (time .Hour ),
21+ expectedSettings : TimeToLiveSettings {
22+ ColumnName : "a" ,
23+ Mode : TimeToLiveModeValueSinceUnixEpoch ,
24+ ExpireAfterSeconds : uint32 (time .Hour .Seconds ()),
25+ ColumnUnit : func () * TimeToLiveUnit {
26+ u := TimeToLiveUnitSeconds
27+ return & u
28+ }(),
29+ },
30+ },
31+ {
32+ fluentSettings : TimeToLiveSettings {}.
33+ WithColumnName ("a" ).
34+ ModeDate ().
35+ ExpireAfter (time .Hour ),
36+ expectedSettings : TimeToLiveSettings {
37+ ColumnName : "a" ,
38+ Mode : TimeToLiveModeDateType ,
39+ ExpireAfterSeconds : uint32 (time .Hour .Seconds ()),
40+ },
41+ },
42+ {
43+ fluentSettings : TimeToLiveSettings {}.
44+ WithColumnName ("a" ).
45+ ModeSinceEpoch ().
46+ ColumnUnitSeconds ().
47+ ExpireAfter (time .Hour ),
48+ expectedSettings : TimeToLiveSettings {
49+ ColumnName : "a" ,
50+ Mode : TimeToLiveModeValueSinceUnixEpoch ,
51+ ExpireAfterSeconds : uint32 (time .Hour .Seconds ()),
52+ ColumnUnit : func () * TimeToLiveUnit {
53+ u := TimeToLiveUnitSeconds
54+ return & u
55+ }(),
56+ },
57+ },
58+ {
59+ fluentSettings : TimeToLiveSettings {}.
60+ WithColumnName ("a" ).
61+ ColumnUnitSeconds ().
62+ ExpireAfter (time .Hour ),
2063 expectedSettings : TimeToLiveSettings {
2164 ColumnName : "a" ,
2265 Mode : TimeToLiveModeValueSinceUnixEpoch ,
@@ -27,11 +70,54 @@ func TestTimeToLiveSettingsFluentModifiers(t *testing.T) {
2770 }(),
2871 },
2972 },
73+ {
74+ fluentSettings : TimeToLiveSettings {}.
75+ WithColumnName ("a" ).
76+ ColumnUnitMilliseconds ().
77+ ExpireAfter (time .Hour ),
78+ expectedSettings : TimeToLiveSettings {
79+ ColumnName : "a" ,
80+ Mode : TimeToLiveModeValueSinceUnixEpoch ,
81+ ExpireAfterSeconds : uint32 (time .Hour .Seconds ()),
82+ ColumnUnit : func () * TimeToLiveUnit {
83+ u := TimeToLiveUnitMilliseconds
84+ return & u
85+ }(),
86+ },
87+ },
88+ {
89+ fluentSettings : TimeToLiveSettings {}.
90+ WithColumnName ("a" ).
91+ ColumnUnitMicroseconds ().
92+ ExpireAfter (time .Hour ),
93+ expectedSettings : TimeToLiveSettings {
94+ ColumnName : "a" ,
95+ Mode : TimeToLiveModeValueSinceUnixEpoch ,
96+ ExpireAfterSeconds : uint32 (time .Hour .Seconds ()),
97+ ColumnUnit : func () * TimeToLiveUnit {
98+ u := TimeToLiveUnitMicroseconds
99+ return & u
100+ }(),
101+ },
102+ },
103+ {
104+ fluentSettings : TimeToLiveSettings {}.
105+ WithColumnName ("a" ).
106+ ColumnUnitNanoseconds ().
107+ ExpireAfter (time .Hour ),
108+ expectedSettings : TimeToLiveSettings {
109+ ColumnName : "a" ,
110+ Mode : TimeToLiveModeValueSinceUnixEpoch ,
111+ ExpireAfterSeconds : uint32 (time .Hour .Seconds ()),
112+ ColumnUnit : func () * TimeToLiveUnit {
113+ u := TimeToLiveUnitNanoseconds
114+ return & u
115+ }(),
116+ },
117+ },
30118 } {
31119 t .Run ("" , func (t * testing.T ) {
32- if ! reflect .DeepEqual (tt .fluentSettings , tt .expectedSettings ) {
33- t .Errorf ("unexpected ttl settings: %v, expectedSettings: %v" , tt .fluentSettings , tt .expectedSettings )
34- }
120+ require .Equal (t , tt .fluentSettings , tt .expectedSettings )
35121 })
36122 }
37123}
0 commit comments