From d075aac77ca8f4ffb473c78f2ed670ca0b991ecf Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Sat, 30 Nov 2013 20:18:56 -0500 Subject: [PATCH 1/5] Added api_test.go --- api_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 api_test.go diff --git a/api_test.go b/api_test.go new file mode 100644 index 0000000..42bc887 --- /dev/null +++ b/api_test.go @@ -0,0 +1,44 @@ +package main + +import ( + "testing" + "fmt" +) + +type PGP struct { + Key string + Valid bool +} + +func TestPGP(t *testing.T) { + fmt.Println("Testing PGP regex") + + testPGP := []PGP{ + {"CAFEBABE", true}, + {"caFeD00d", true}, + {"12345678", true}, + {"ORANGEEE", false}, + {"12O21333", false}, + {"CAFEBABECAFEBABE", true}, + {"C2AccAb3CDDDad2F", true}, + {"1234567890ABCDEF", true}, + {"3ABC12AAAAC2134D", true}, + {"ABC12CCAADD333X9", false}, + } + + for i, p := range testPGP { + fmt.Print(i) + fmt.Print(" - " + p.Key + " is valid? ") + fmt.Print(PGPRegexp.Match([]byte(p.Key))) + fmt.Print(" (should be ") + fmt.Print(p.Valid) + fmt.Println(")") + if PGPRegexp.Match([]byte(p.Key)) != p.Valid { + t.Errorf("%s returned %v when it should have returned %v!", p.Key, !p.Valid, p.Valid) + } + } +} + +func TestEmail(t *testing.T) { + +} From 601bf095c2b33e837945f8218245e1e9c3b08da2 Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Wed, 4 Dec 2013 16:08:05 -0500 Subject: [PATCH 2/5] Started on email test. This isn't completely done yet, for we have some stuff to talk about regarding emails. --- api_test.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/api_test.go b/api_test.go index 42bc887..534fdfc 100644 --- a/api_test.go +++ b/api_test.go @@ -5,7 +5,7 @@ import ( "fmt" ) -type PGP struct { +type Test struct { Key string Valid bool } @@ -13,7 +13,7 @@ type PGP struct { func TestPGP(t *testing.T) { fmt.Println("Testing PGP regex") - testPGP := []PGP{ + test := []Test{ {"CAFEBABE", true}, {"caFeD00d", true}, {"12345678", true}, @@ -26,7 +26,7 @@ func TestPGP(t *testing.T) { {"ABC12CCAADD333X9", false}, } - for i, p := range testPGP { + for i, p := range test { fmt.Print(i) fmt.Print(" - " + p.Key + " is valid? ") fmt.Print(PGPRegexp.Match([]byte(p.Key))) @@ -40,5 +40,26 @@ func TestPGP(t *testing.T) { } func TestEmail(t *testing.T) { + fmt.Println("Testing Email regex") + test := []Test{ + {"nodeatlaszz323@example.com", true}, + {"123@exle.ch", true}, + {"abc+xyz@some.site.co.uk", true}, + {"thisisanemail.com", false}, + {"yooo@", false}, + } + + for i, e := range test { + fmt.Print(i) + fmt.Print(" - " + e.Key + " is valid? ") + fmt.Print(EmailRegexp.Match([]byte(e.Key))) + fmt.Print(" (should be ") + fmt.Print(e.Valid) + fmt.Println(")") + if EmailRegexp.Match([]byte(e.Key)) != e.Valid { + t.Errorf("%s returned %v when it should have returned %v!", e.Key, !e.Valid, e.Valid) + } + } + } From af08cf8bf7a5edacf637be280b8e876ebc8ea208 Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Thu, 5 Dec 2013 07:32:33 -0500 Subject: [PATCH 3/5] Test read config --- config_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 config_test.go diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..7ad9b12 --- /dev/null +++ b/config_test.go @@ -0,0 +1,16 @@ +package main + +import ( + "testing" + "fmt" +) + +var err error + +func TestReadConfig(t *testing.T) { + fmt.Println("Testing Read Config") + _, err = ReadConfig("conf.json.example") + if err != nil { + t.Errorf("Could not read config: %s", err) + } +} From 67675037c28e2dd3e8b81bcff8976b9a7f7248d6 Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Thu, 5 Dec 2013 07:37:26 -0500 Subject: [PATCH 4/5] TestWriteConfig --- config_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/config_test.go b/config_test.go index 7ad9b12..3234f4a 100644 --- a/config_test.go +++ b/config_test.go @@ -3,14 +3,28 @@ package main import ( "testing" "fmt" + "os" ) var err error +var conf *Config func TestReadConfig(t *testing.T) { fmt.Println("Testing Read Config") - _, err = ReadConfig("conf.json.example") + conf, err = ReadConfig("conf.json.example") if err != nil { t.Errorf("Could not read config: %s", err) } } + +func TestWriteConfig(t *testing.T) { + fmt.Println("Testing Write Config") + err = WriteConfig(conf, "conf.write.test") + if err != nil { + t.Errorf("Could not write config: %s", err) + } + err = os.Remove("conf.write.test") + if err != nil { + t.Errorf("Could not delete test config: %s", err) + } +} From 75b447001cbaf6c6ee9e9be777b1e188d62177d6 Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Thu, 5 Dec 2013 07:42:55 -0500 Subject: [PATCH 5/5] Added two empty func tests, and added some comments --- config_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/config_test.go b/config_test.go index 3234f4a..69ff46f 100644 --- a/config_test.go +++ b/config_test.go @@ -10,6 +10,7 @@ var err error var conf *Config func TestReadConfig(t *testing.T) { + // func ReadConfig(path string) (conf *Config, err error) fmt.Println("Testing Read Config") conf, err = ReadConfig("conf.json.example") if err != nil { @@ -18,6 +19,7 @@ func TestReadConfig(t *testing.T) { } func TestWriteConfig(t *testing.T) { + // func WriteConfig(conf *Config, path string) (err error) fmt.Println("Testing Write Config") err = WriteConfig(conf, "conf.write.test") if err != nil { @@ -28,3 +30,15 @@ func TestWriteConfig(t *testing.T) { t.Errorf("Could not delete test config: %s", err) } } + +func TestMarshalJSON(t *testing.T) { + // func (d Duration) MarshalJSON() ([]byte, error) +} + +func TestUnmarshalJSON(t *testing.T) { + // There are two funcs for UnmarshallJSON, so this test func + // will test them both rather than having two more test funcs + // + // func (d *Duration) UnmarshalJSON(b []byte) error + // func (n *IPNet) UnmarshalJSON(b []byte) error +}