Test notes
parent
c88fed0929
commit
b73a962556
|
|
@ -1 +1,18 @@
|
||||||
package notes
|
package notes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"local/notes-server/config"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreate(t *testing.T) {
|
||||||
|
config.Root = "/tmp"
|
||||||
|
n := &Notes{}
|
||||||
|
resp, err := n.Create("/create/a")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if resp != "/edit/a" {
|
||||||
|
t.Error(resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,20 @@
|
||||||
package notes
|
package notes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"local/notes-server/config"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDelete(t *testing.T) {
|
||||||
|
config.Root = "/tmp"
|
||||||
|
ioutil.WriteFile("/tmp/a", []byte("hi"), os.ModePerm)
|
||||||
|
n := &Notes{}
|
||||||
|
if err := n.Delete("/notes/a"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat("/tmp/a"); err == nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,21 @@
|
||||||
package notes
|
package notes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"local/notes-server/config"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEdit(t *testing.T) {
|
||||||
|
config.Root = "/tmp"
|
||||||
|
n := &Notes{}
|
||||||
|
if body, err := n.Edit("/notes/a"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if !strings.Contains(body, "/submit/a") {
|
||||||
|
t.Error(body)
|
||||||
|
}
|
||||||
|
config.Root = "/usr"
|
||||||
|
if _, err := n.Edit("/notes/local"); err == nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,22 @@
|
||||||
package notes
|
package notes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"local/notes-server/config"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSubmit(t *testing.T) {
|
||||||
|
config.Root = "/tmp"
|
||||||
|
n := &Notes{}
|
||||||
|
if err := n.Submit("/submit/a", "a"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if b, err := ioutil.ReadFile("/tmp/a"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else if string(b) != "a" {
|
||||||
|
t.Error(string(b))
|
||||||
|
} else if err := os.Remove("/tmp/a"); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue