ntfy/server/util_test.go

30 lines
896 B
Go
Raw Normal View History

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