ntfy/server/util_test.go

30 lines
896 B
Go
Raw Normal View History

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