This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from RobotsAndPencils/headers
add tests and documentation for headers
- Loading branch information
Showing
3 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package push | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestHeaders(t *testing.T) { | ||
headers := Headers{ | ||
ID: "uuid", | ||
Expiration: time.Unix(12622780800, 0), | ||
LowPriority: true, | ||
Topic: "bundle-id", | ||
} | ||
|
||
reqHeader := http.Header{} | ||
headers.set(reqHeader) | ||
|
||
testHeader(t, reqHeader, "apns-id", "uuid") | ||
testHeader(t, reqHeader, "apns-expiration", "12622780800") | ||
testHeader(t, reqHeader, "apns-priority", "5") | ||
testHeader(t, reqHeader, "apns-topic", "bundle-id") | ||
} | ||
|
||
func TestNilHeader(t *testing.T) { | ||
var headers *Headers | ||
reqHeader := http.Header{} | ||
headers.set(reqHeader) | ||
|
||
testHeader(t, reqHeader, "apns-id", "") | ||
testHeader(t, reqHeader, "apns-expiration", "") | ||
testHeader(t, reqHeader, "apns-priority", "") | ||
testHeader(t, reqHeader, "apns-topic", "") | ||
} | ||
|
||
func TestEmptyHeaders(t *testing.T) { | ||
headers := Headers{} | ||
reqHeader := http.Header{} | ||
headers.set(reqHeader) | ||
|
||
testHeader(t, reqHeader, "apns-id", "") | ||
testHeader(t, reqHeader, "apns-expiration", "") | ||
testHeader(t, reqHeader, "apns-priority", "") | ||
testHeader(t, reqHeader, "apns-topic", "") | ||
} | ||
|
||
func testHeader(t *testing.T, reqHeader http.Header, key, expected string) { | ||
actual := reqHeader.Get(key) | ||
if actual != expected { | ||
t.Errorf("Expected %s %q, got %q.", key, expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters