| 9 | ) |
| 10 | |
| 11 | func TestResourceMonitorQueue(t *testing.T) { |
| 12 | t.Parallel() |
| 13 | |
| 14 | tests := []struct { |
| 15 | name string |
| 16 | pushCount int |
| 17 | expected []resourcesmonitor.Datapoint |
| 18 | }{ |
| 19 | { |
| 20 | name: "Push zero", |
| 21 | pushCount: 0, |
| 22 | expected: []resourcesmonitor.Datapoint{}, |
| 23 | }, |
| 24 | { |
| 25 | name: "Push less than capacity", |
| 26 | pushCount: 3, |
| 27 | expected: []resourcesmonitor.Datapoint{ |
| 28 | {Memory: &resourcesmonitor.MemoryDatapoint{Total: 1, Used: 1}}, |
| 29 | {Memory: &resourcesmonitor.MemoryDatapoint{Total: 2, Used: 2}}, |
| 30 | {Memory: &resourcesmonitor.MemoryDatapoint{Total: 3, Used: 3}}, |
| 31 | }, |
| 32 | }, |
| 33 | { |
| 34 | name: "Push exactly capacity", |
| 35 | pushCount: 20, |
| 36 | expected: func() []resourcesmonitor.Datapoint { |
| 37 | var result []resourcesmonitor.Datapoint |
| 38 | for i := 1; i <= 20; i++ { |
| 39 | result = append(result, resourcesmonitor.Datapoint{ |
| 40 | Memory: &resourcesmonitor.MemoryDatapoint{ |
| 41 | Total: int64(i), |
| 42 | Used: int64(i), |
| 43 | }, |
| 44 | }) |
| 45 | } |
| 46 | return result |
| 47 | }(), |
| 48 | }, |
| 49 | { |
| 50 | name: "Push more than capacity", |
| 51 | pushCount: 25, |
| 52 | expected: func() []resourcesmonitor.Datapoint { |
| 53 | var result []resourcesmonitor.Datapoint |
| 54 | for i := 6; i <= 25; i++ { |
| 55 | result = append(result, resourcesmonitor.Datapoint{ |
| 56 | Memory: &resourcesmonitor.MemoryDatapoint{ |
| 57 | Total: int64(i), |
| 58 | Used: int64(i), |
| 59 | }, |
| 60 | }) |
| 61 | } |
| 62 | return result |
| 63 | }(), |
| 64 | }, |
| 65 | } |
| 66 | |
| 67 | for _, tt := range tests { |
| 68 | t.Run(tt.name, func(t *testing.T) { |