(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestAddAndRemove(t *testing.T) { |
| 187 | wrapper, wrapperCancel := initConfig() |
| 188 | defer wrapperCancel() |
| 189 | lim := newLimiter(device1, wrapper) |
| 190 | |
| 191 | addedDevice, _ := protocol.DeviceIDFromString("XZJ4UNS-ENI7QGJ-J45DT6G-QSGML2K-6I4XVOG-NAZ7BF5-2VAOWNT-TFDOMQU") |
| 192 | addDevConf := newDeviceConfiguration(wrapper, addedDevice, "addedDevice") |
| 193 | addDevConf.MaxRecvKbps = 120 |
| 194 | addDevConf.MaxSendKbps = 240 |
| 195 | |
| 196 | waiter, _ := wrapper.Modify(func(cfg *config.Configuration) { |
| 197 | cfg.SetDevice(addDevConf) |
| 198 | }) |
| 199 | waiter.Wait() |
| 200 | waiter, _ = wrapper.RemoveDevice(device3) |
| 201 | waiter.Wait() |
| 202 | |
| 203 | expectedR := map[protocol.DeviceID]*rate.Limiter{ |
| 204 | device2: rate.NewLimiter(rate.Limit(dev2Conf.MaxRecvKbps*1024), limiterBurstSize), |
| 205 | device4: rate.NewLimiter(rate.Inf, limiterBurstSize), |
| 206 | addedDevice: rate.NewLimiter(rate.Limit(addDevConf.MaxRecvKbps*1024), limiterBurstSize), |
| 207 | } |
| 208 | |
| 209 | expectedW := map[protocol.DeviceID]*rate.Limiter{ |
| 210 | device2: rate.NewLimiter(rate.Limit(dev2Conf.MaxSendKbps*1024), limiterBurstSize), |
| 211 | device4: rate.NewLimiter(rate.Inf, limiterBurstSize), |
| 212 | addedDevice: rate.NewLimiter(rate.Limit(addDevConf.MaxSendKbps*1024), limiterBurstSize), |
| 213 | } |
| 214 | actualR := lim.deviceReadLimiters |
| 215 | actualW := lim.deviceWriteLimiters |
| 216 | |
| 217 | checkActualAndExpected(t, actualR, actualW, expectedR, expectedW) |
| 218 | } |
| 219 | |
| 220 | func TestLimitedWriterWrite(t *testing.T) { |
| 221 | // Check that the limited writer writes the correct data in the correct manner. |
nothing calls this directly
no test coverage detected