Skip to content

Commit

Permalink
sniblocking: start improving the quality of unit tests
Browse files Browse the repository at this point in the history
Part of #684
  • Loading branch information
bassosimone committed Jul 1, 2020
1 parent 68dcf88 commit d3b8a89
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
77 changes: 76 additions & 1 deletion experiment/sniblocking/sniblocking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,48 @@ func TestUnitMeasureoneCancelledContext(t *testing.T) {
if *result.Failure != modelx.FailureGenericTimeoutError {
t.Fatal("unexpected failure")
}
if result.Agent != "" {
t.Fatal("not the expected Agent")
}
if result.BootstrapTime != 0.0 {
t.Fatal("not the expected BootstrapTime")
}
if result.DNSCache != nil {
t.Fatal("not the expected DNSCache")
}
if result.FailedOperation != nil {
t.Fatal("not the expected FailedOperation")
}
if result.Failure == nil || *result.Failure != modelx.FailureGenericTimeoutError {
t.Fatal("not the expected failure")
}
if result.NetworkEvents != nil {
t.Fatal("not the expected NetworkEvents")
}
if result.Queries != nil {
t.Fatal("not the expected Queries")
}
if result.Requests != nil {
t.Fatal("not the expected Requests")
}
if result.SOCKSProxy != "" {
t.Fatal("not the expected SOCKSProxy")
}
if result.TCPConnect != nil {
t.Fatal("not the expected TCPConnect")
}
if result.TLSHandshakes != nil {
t.Fatal("not the expected TLSHandshakes")
}
if result.Tunnel != "" {
t.Fatal("not the expected Tunnel")
}
if result.SNI != "kernel.org" {
t.Fatal("unexpected SNI")
}
if result.THAddress != "example.com:443" {
t.Fatal("unexpected THAddress")
}
}

func TestUnitMeasureoneSuccess(t *testing.T) {
Expand All @@ -204,12 +243,48 @@ func TestUnitMeasureoneSuccess(t *testing.T) {
"kernel.org",
"example.com:443",
)
if *result.Failure != modelx.FailureSSLInvalidHostname {
if result.Agent != "redirect" {
t.Fatal("not the expected Agent")
}
if result.BootstrapTime != 0.0 {
t.Fatal("not the expected BootstrapTime")
}
if result.DNSCache != nil {
t.Fatal("not the expected DNSCache")
}
if result.FailedOperation == nil || *result.FailedOperation != modelx.TLSHandshakeOperation {
t.Fatal("not the expected FailedOperation")
}
if result.Failure == nil || *result.Failure != modelx.FailureSSLInvalidHostname {
t.Fatal("unexpected failure")
}
if len(result.NetworkEvents) < 1 {
t.Fatal("not the expected NetworkEvents")
}
if len(result.Queries) < 1 {
t.Fatal("not the expected Queries")
}
if result.Requests != nil {
t.Fatal("not the expected Requests")
}
if result.SOCKSProxy != "" {
t.Fatal("not the expected SOCKSProxy")
}
if len(result.TCPConnect) < 1 {
t.Fatal("not the expected TCPConnect")
}
if len(result.TLSHandshakes) < 1 {
t.Fatal("not the expected TLSHandshakes")
}
if result.Tunnel != "" {
t.Fatal("not the expected Tunnel")
}
if result.SNI != "kernel.org" {
t.Fatal("unexpected SNI")
}
if result.THAddress != "example.com:443" {
t.Fatal("unexpected THAddress")
}
}

func TestUnitMeasureonewithcacheWorks(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion experiment/urlgetter/urlgetter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type TestKeys struct {
NetworkEvents []archival.NetworkEvent `json:"network_events"`
Queries []archival.DNSQueryEntry `json:"queries"`
Requests []archival.RequestEntry `json:"requests"`
TCPConnect []archival.TCPConnectEntry `json:"tcp_connect"`
SOCKSProxy string `json:"socksproxy,omitempty"`
TCPConnect []archival.TCPConnectEntry `json:"tcp_connect"`
TLSHandshakes []archival.TLSHandshake `json:"tls_handshakes"`
Tunnel string `json:"tunnel,omitempty"`

Expand Down

0 comments on commit d3b8a89

Please sign in to comment.