mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-30 22:34:18 -05:00
additional tests for imageproxy-sign
This commit is contained in:
parent
ca8fe71a0a
commit
6975320eb4
1 changed files with 43 additions and 0 deletions
|
@ -10,6 +10,30 @@ import (
|
|||
|
||||
var key = "secret"
|
||||
|
||||
func TestMainFunc(t *testing.T) {
|
||||
os.Args = []string{"imageproxy-sign", "-key", key, "http://example.com/#0x0"}
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Errorf("error creating pipe: %v", err)
|
||||
}
|
||||
defer r.Close()
|
||||
os.Stdout = w
|
||||
|
||||
main()
|
||||
w.Close()
|
||||
|
||||
output, err := ioutil.ReadAll(r)
|
||||
got := string(output)
|
||||
if err != nil {
|
||||
t.Errorf("error reading from pipe: %v", err)
|
||||
}
|
||||
|
||||
want := "url: http://example.com/#0x0\nsignature: pwlnJ3bVazxg2nQxClimqT0VnNxUm5W0cdyg1HpKUPY=\n"
|
||||
if got != want {
|
||||
t.Errorf("main output %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
s := "http://example.com/image.jpg#0x0"
|
||||
|
||||
|
@ -36,6 +60,25 @@ func TestSign_URLOnly(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSign_Errors(t *testing.T) {
|
||||
var err error
|
||||
|
||||
tests := []struct {
|
||||
key, url string
|
||||
}{
|
||||
{"", ""},
|
||||
{"", "%"},
|
||||
{"@/does/not/exist", "s"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
_, err = sign(tt.key, tt.url, false)
|
||||
if err == nil {
|
||||
t.Errorf("sign(%q, %q, false) did not return expected error", tt.key, tt.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseKey(t *testing.T) {
|
||||
k, err := parseKey(key)
|
||||
got := string(k)
|
||||
|
|
Loading…
Reference in a new issue