-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement functionality to terminate ndt7 tests early given a client …
…parameter (#390) * Initial early exit changes * Use parameter * Address comments * Move Params to sender package
- Loading branch information
1 parent
ec2a361
commit 5824ad0
Showing
7 changed files
with
183 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Package handler implements the WebSocket handler for ndt7. | ||
package handler | ||
|
||
import ( | ||
"net/url" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/m-lab/ndt-server/ndt7/download/sender" | ||
"github.com/m-lab/ndt-server/ndt7/spec" | ||
) | ||
|
||
func Test_validateEarlyExit(t *testing.T) { | ||
type args struct { | ||
values url.Values | ||
} | ||
tests := []struct { | ||
name string | ||
values url.Values | ||
want *sender.Params | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid-param", | ||
values: url.Values{"early_exit": {spec.ValidEarlyExitValues[0]}}, | ||
want: &sender.Params{ | ||
IsEarlyExit: true, | ||
MaxBytes: 250000000, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid-param", | ||
values: url.Values{"early_exit": {"123"}}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "missing-value", | ||
values: url.Values{"early_exit": {""}}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "absent-param", | ||
values: url.Values{"foo": {"bar"}}, | ||
want: &sender.Params{ | ||
IsEarlyExit: false, | ||
MaxBytes: 0, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := validateEarlyExit(tt.values) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("validateEarlyExit() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("validateEarlyExit() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters