1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-22 19:33:27 +01:00
ntfy/server/util_test.go

30 lines
896 B
Go
Raw Normal View History

2022-01-16 05:17:46 +01:00
package server
import (
"github.com/stretchr/testify/require"
2022-02-01 14:47:01 +01:00
"net/http"
2022-01-16 05:17:46 +01:00
"testing"
)
2022-02-01 14:47:01 +01:00
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)
2022-01-16 05:17:46 +01:00
2022-02-01 14:47:01 +01:00
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)
2022-01-16 05:17:46 +01:00
2022-02-01 14:47:01 +01:00
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)
2022-01-16 05:17:46 +01:00
}