| 1 | package policyutil |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | type refCounter struct { |
| 8 | count int |
| 9 | } |
| 10 | |
| 11 | func (r refCounter) GetReferenceCount() int { |
| 12 | return r.count |
| 13 | } |
| 14 | |
| 15 | func TestGetReferenceCount(t *testing.T) { |
| 16 | tests := []struct { |
| 17 | name string |
| 18 | input any |
| 19 | want int |
| 20 | }{ |
| 21 | { |
| 22 | name: "with GetReferenceCount() method", |
| 23 | input: refCounter{count: 5}, |
| 24 | want: 5, |
| 25 | }, |
| 26 | { |
| 27 | name: "without GetReferenceCount() method", |
| 28 | input: "sample string", |
| 29 | want: 1, |
| 30 | }, |
| 31 | } |
| 32 | |
| 33 | for _, test := range tests { |
| 34 | t.Run(test.name, func(t *testing.T) { |
| 35 | output := GetReferenceCount(test.input) |
| 36 | if output != test.want { |
| 37 | t.Errorf("want %d, got %d", test.want, output) |
| 38 | } |
| 39 | }) |
| 40 | } |
| 41 | } |