Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | package idempotency |
||
2 | |||
3 | // NOpIdempotencyGenerator is a dummy implementation of the |
||
4 | // IdempotencyKeyGenerator interface. |
||
5 | // |
||
6 | // Good for testing or when a predictable result is required. |
||
7 | type nOpIdempotencyGenerator struct { |
||
8 | expected string |
||
9 | } |
||
10 | |||
11 | const ( |
||
12 | TestKeyExpected = "test_ikg_key" |
||
13 | ) |
||
14 | |||
15 | // Generate encapsulates the logic to return a string representation of |
||
16 | // a unique idempotency key. |
||
17 | func (nopIKG nOpIdempotencyGenerator) Generate() string { |
||
18 | 1 | return nopIKG.expected |
|
19 | } |
||
20 | |||
21 | // NewNopGenerator returns a dummy implementation of the |
||
22 | // IdempotencyKeyGenerator interface. |
||
23 | // |
||
24 | // Good for testing or when a predictable result is required. |
||
25 | // |
||
26 | // If exp is an empty string, then TestKeyExpected is used as |
||
27 | // default value for the NOpGenerator. |
||
28 | func NewNopGenerator(exp string) KeyGenerator { |
||
29 | 1 | if exp == "" { |
|
30 | 1 | exp = TestKeyExpected |
|
31 | } |
||
32 | |||
33 | 1 | return nOpIdempotencyGenerator{ |
|
34 | expected: exp, |
||
35 | } |
||
37 |