cache: Per-client fair-share bandwidth on table uplink
This commit is contained in:
@@ -211,3 +211,72 @@ func TestValidate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestValidateUplinkBandwidth(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
mutate func(*Config)
|
||||
wantErr bool
|
||||
errSub string
|
||||
}{
|
||||
{
|
||||
name: "empty uplink ok",
|
||||
mutate: func(c *Config) {
|
||||
c.UplinkBandwidth = ""
|
||||
c.MaxBytesPerClientPerSec = 0
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "zero uplink ok",
|
||||
mutate: func(c *Config) {
|
||||
c.UplinkBandwidth = "0"
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid human size",
|
||||
mutate: func(c *Config) {
|
||||
c.UplinkBandwidth = "10MB"
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "invalid uplink",
|
||||
mutate: func(c *Config) {
|
||||
c.UplinkBandwidth = "not-a-size"
|
||||
},
|
||||
wantErr: true,
|
||||
errSub: "uplink_bandwidth",
|
||||
},
|
||||
{
|
||||
name: "negative max bytes",
|
||||
mutate: func(c *Config) {
|
||||
c.MaxBytesPerClientPerSec = -1
|
||||
},
|
||||
wantErr: true,
|
||||
errSub: "max_bytes_per_client_per_sec",
|
||||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
c := GetDefaultConfig()
|
||||
tt.mutate(&c)
|
||||
err := c.Validate()
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("Validate() error = nil, wantErr")
|
||||
}
|
||||
if tt.errSub != "" && !contains(err.Error(), tt.errSub) {
|
||||
t.Fatalf("Validate() error %q does not contain %q", err.Error(), tt.errSub)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("Validate() unexpected error: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func contains(s, sub string) bool {
|
||||
return strings.Contains(s, sub)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user