[tor-commits] [goptlib/master] Add tests for error functions.

dcf at torproject.org dcf at torproject.org
Fri Mar 31 07:20:34 UTC 2017


commit c1cf6bee9adc78bce3ceed72d6b8cd3ce50976ae
Author: David Fifield <david at bamsoftware.com>
Date:   Fri Mar 31 00:14:45 2017 -0700

    Add tests for error functions.
    
    The ProxyError test currently panics because of a bug in ProxyError.
    
    --- FAIL: TestErrors (0.00s)
    panic: keyword "PROXY-ERROR %s\n" contains forbidden bytes [recovered]
            panic: keyword "PROXY-ERROR %s\n" contains forbidden bytes
---
 pt_test.go | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/pt_test.go b/pt_test.go
index fb9e61f..f6b9ea8 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -13,6 +13,32 @@ import (
 	"testing"
 )
 
+func TestErrors(t *testing.T) {
+	Stdout = ioutil.Discard
+
+	var err error
+	err = envError("XYZ")
+	if err.Error() != "ENV-ERROR XYZ" {
+		t.Errorf("unexpected string %q from envError", err.Error())
+	}
+	err = versionError("XYZ")
+	if err.Error() != "VERSION-ERROR XYZ" {
+		t.Errorf("unexpected string %q from versionError", err.Error())
+	}
+	err = CmethodError("method", "XYZ")
+	if err.Error() != "CMETHOD-ERROR method XYZ" {
+		t.Errorf("unexpected string %q from CmethodError", err.Error())
+	}
+	err = SmethodError("method", "XYZ")
+	if err.Error() != "SMETHOD-ERROR method XYZ" {
+		t.Errorf("unexpected string %q from SmethodError", err.Error())
+	}
+	err = ProxyError("XYZ")
+	if err.Error() != "PROXY-ERROR XYZ" {
+		t.Errorf("unexpected string %q from ProxyError", err.Error())
+	}
+}
+
 func TestKeywordIsSafe(t *testing.T) {
 	tests := [...]struct {
 		keyword  string





More information about the tor-commits mailing list