Skip to content

Commit

Permalink
Add test for SERVER_MODE=download (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mat committed Oct 30, 2019
1 parent 258777f commit 33afda5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions besticon/iconserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -61,6 +62,27 @@ func TestGetIcon(t *testing.T) {
assertStringEquals(t, "https://www.apple.com/apple-touch-icon.png", w.Header().Get("Location"))
}

func TestGetIconWithDownloadMode(t *testing.T) {
os.Setenv("SERVER_MODE", "download")
req, err := http.NewRequest("GET", "/icon?url=apple.com&size=120", nil)
if err != nil {
log.Fatal(err)
}

w := httptest.NewRecorder()
iconHandler(w, req)

assertStringEquals(t, "200", fmt.Sprintf("%d", w.Code))
assertStringEquals(t, "max-age=2592000", w.Header().Get("Cache-Control"))
assertStringEquals(t, "image/png", w.Header().Get("Content-Type"))
assertStringEquals(t, "", w.Header().Get("Location"))

// Make sure we return some data
assertIntegerInInterval(t, 2000, 10000, len(w.Body.String()))

os.Setenv("SERVER_MODE", "")
}

func TestGetIconWithFallBackURL(t *testing.T) {
req, err := http.NewRequest("GET", "/icon?url=apple.com&size=400&fallback_icon_url=http%3A%2F%2Fexample.com", nil)
if err != nil {
Expand Down

0 comments on commit 33afda5

Please sign in to comment.