Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Tests #187

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
@@ -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{
{"[email protected]", true},
{"[email protected]", true},
{"[email protected]", 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)
}
}

}
44 changes: 44 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -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
}