diff --git a/api_test.go b/api_test.go new file mode 100644 index 0000000..534fdfc --- /dev/null +++ b/api_test.go @@ -0,0 +1,65 @@ +package main + +import ( + "testing" + "fmt" +) + +type Test struct { + Key string + Valid bool +} + +func TestPGP(t *testing.T) { + fmt.Println("Testing PGP regex") + + test := []Test{ + {"CAFEBABE", true}, + {"caFeD00d", true}, + {"12345678", true}, + {"ORANGEEE", false}, + {"12O21333", false}, + {"CAFEBABECAFEBABE", true}, + {"C2AccAb3CDDDad2F", true}, + {"1234567890ABCDEF", true}, + {"3ABC12AAAAC2134D", true}, + {"ABC12CCAADD333X9", false}, + } + + for i, p := range test { + 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) { + 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) + } + } + +} diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..69ff46f --- /dev/null +++ b/config_test.go @@ -0,0 +1,44 @@ +package main + +import ( + "testing" + "fmt" + "os" +) + +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 { + t.Errorf("Could not read config: %s", err) + } +} + +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 { + 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) + } +} + +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 +}