summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus_Arch2015-02-22 17:20:18 +0100
committerHorus_Arch2015-02-22 17:20:18 +0100
commit00b28812fb5ab68156ead5b45b66740a4d5ca688 (patch)
tree1db4545d5925943a1a761226ac378bb14d9204b7
parentbdb2d33a30765a25be3dd8c82b92517efa00dda8 (diff)
downloadstatuspage-00b28812fb5ab68156ead5b45b66740a4d5ca688.tar.gz
Unit tests are now triggered by build tags.
-rw-r--r--app/Makefile22
-rw-r--r--app/dependecies_test.go6
-rw-r--r--app/test.go4
-rw-r--r--app/utilities.go21
-rw-r--r--app/utilities_test.go11
5 files changed, 47 insertions, 17 deletions
diff --git a/app/Makefile b/app/Makefile
index e10dbc4..c847c75 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -28,14 +28,10 @@ APP:=statuspage
all: kill build run
clean: kill
- @echo "Removing import file..."
- @rm $(IMPORT_FILE) || true
- @echo "Removing sqlite3 database..."
- @rm $(STATUS_DB_CREDENTIALS) || true
- @echo "Removing tar archiv..."
- @rm ../$(APP).tar.gz 1>&2 2>/dev/null || true
- @echo "Removing binary..."
- @rm $(APP)
+ @(rm $(IMPORT_FILE) 2>/dev/null && echo "Removing import file..." ) || true
+ @(rm $(STATUS_DB_CREDENTIALS) 2>/dev/null && echo "Removing sqlite3 database..." ) || true
+ @(rm ../$(APP).tar.gz 1>&2 2>/dev/null echo && "Removing tar archiv...") || true
+ @(rm $(APP) && echo "Removing binary ($(APP))...") || true
@echo "Done."
build: import
@@ -80,10 +76,10 @@ pack:
(echo "Run \"make build\" first." && exit 1)
test:
- go test -race -run '^(Database|Redis)'
+ go test -v -race -tags general
-test_all:
- go test -race
+test_all: import
+ go test -v -race -tags all
-test_dependencies:
- go test -race -run '(Database|Redis)'
+test_dependencies: import
+ go test -v -race -tags dep
diff --git a/app/dependecies_test.go b/app/dependecies_test.go
index d220f96..dd42495 100644
--- a/app/dependecies_test.go
+++ b/app/dependecies_test.go
@@ -1,3 +1,5 @@
+// +build all dep
+
package main
import (
@@ -6,9 +8,11 @@ import (
func TestDatabase(t *testing.T) {
// h := Host{Url: "http://example.com"}
+ InitDB()
err := Db.DB().Ping()
if err != nil {
- t.Fatal("No database connection established.")
+ //t.Fatal("No database connection established.")
+ t.Error("No database connection established.")
}
}
diff --git a/app/test.go b/app/test.go
index 3cd71bc..200c272 100644
--- a/app/test.go
+++ b/app/test.go
@@ -10,8 +10,8 @@ func insertHost() {
h = Host{Url: "https://iamfabulousadsfadfdsf.de/", Monitored: true, Private: false}
Db.Create(&h)
- c := pool.Get()
- defer c.Close()
+ // c := pool.Get()
+ // defer c.Close()
/*
host := []Host{}
diff --git a/app/utilities.go b/app/utilities.go
index 3ec1b60..a3c3617 100644
--- a/app/utilities.go
+++ b/app/utilities.go
@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/md5"
"encoding/gob"
+ "errors"
"fmt"
"github.com/garyburd/redigo/redis"
"golang.org/x/crypto/bcrypt"
@@ -16,6 +17,21 @@ import (
"time"
)
+/*
+type errorString struct {
+ s string
+}
+
+func (e *errorString) Error() string {
+ return e.s
+}
+
+// New returns an error that formats as the given text.
+func New(text string) error {
+ return &errorString{text}
+}
+*/
+
// Returns headers as map and the content of a webpage as string
func HttpGet(url string) (*http.Response, string, error) {
r, err := http.Get(url)
@@ -78,7 +94,7 @@ func newPool() *redis.Pool {
// Hashs password with bcrypt and returns the string
func HashPassword(password string) (string, error) {
if password == "" {
- return "", nil
+ return "", errors.New("Empty password.")
}
p := []byte(password)
hash, err := bcrypt.GenerateFromPassword(p, 10)
@@ -90,6 +106,9 @@ func HashPassword(password string) (string, error) {
// Verify password and hash
func VerifyPassword(password, hash string) bool {
+ if hash == "" || password == "" {
+ return false
+ }
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
if err != nil {
log.Printf("%s \n", err)
diff --git a/app/utilities_test.go b/app/utilities_test.go
index 7037b2f..5405309 100644
--- a/app/utilities_test.go
+++ b/app/utilities_test.go
@@ -1,3 +1,5 @@
+// +build all general
+
package main
import (
@@ -30,4 +32,13 @@ func TestPassword(t *testing.T) {
if !verify {
t.Fatal("Verifying password failed.")
}
+
+ testHash, err = HashPassword("")
+ if err == nil {
+ t.Fatal("Accepting empty password.")
+ }
+ verify = VerifyPassword("", testHash)
+ if verify {
+ t.Fatal("Verifying empty password.")
+ }
}