1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-01 09:31:18 +01:00
ntfy/server/util_test.go
2022-02-01 08:47:01 -05:00

29 lines
896 B
Go

package server
import (
"github.com/stretchr/testify/require"
"net/http"
"testing"
)
func TestReadBoolParam(t *testing.T) {
r, _ := http.NewRequest("GET", "https://ntfy.sh/mytopic?up=1&firebase=no", nil)
up := readBoolParam(r, false, "x-up", "up")
firebase := readBoolParam(r, true, "x-firebase", "firebase")
require.Equal(t, true, up)
require.Equal(t, false, firebase)
r, _ = http.NewRequest("GET", "https://ntfy.sh/mytopic", nil)
r.Header.Set("X-Up", "yes")
r.Header.Set("X-Firebase", "0")
up = readBoolParam(r, false, "x-up", "up")
firebase = readBoolParam(r, true, "x-firebase", "firebase")
require.Equal(t, true, up)
require.Equal(t, false, firebase)
r, _ = http.NewRequest("GET", "https://ntfy.sh/mytopic", nil)
up = readBoolParam(r, false, "x-up", "up")
firebase = readBoolParam(r, true, "x-up", "up")
require.Equal(t, false, up)
require.Equal(t, true, firebase)
}