63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package api
|
|
|
|
import "testing"
|
|
|
|
func TestServerCookieName(t *testing.T) {
|
|
t.Parallel()
|
|
tests := []struct {
|
|
name string
|
|
secure bool
|
|
expected string
|
|
}{
|
|
{name: "local development", secure: false, expected: "zpa_session"},
|
|
{name: "secure deployment", secure: true, expected: "__Host-zpa_session"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
server := &Server{cookieSecure: tt.secure}
|
|
if got := server.cookieName(); got != tt.expected {
|
|
t.Fatalf("cookieName() = %q, want %q", got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPersianStatus(t *testing.T) {
|
|
t.Parallel()
|
|
if got := persianStatus("Verified"); got != "تأیید شده" {
|
|
t.Fatalf("persianStatus() = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestOptionalNonNegativeInt64(t *testing.T) {
|
|
t.Parallel()
|
|
tests := []struct {
|
|
name, input string
|
|
want *int64
|
|
valid bool
|
|
}{
|
|
{name: "omitted", valid: true},
|
|
{name: "zero", input: "0", want: int64Pointer(0), valid: true},
|
|
{name: "positive", input: "125000", want: int64Pointer(125000), valid: true},
|
|
{name: "negative", input: "-1"},
|
|
{name: "not a number", input: "یک"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, valid := optionalNonNegativeInt64(tt.input)
|
|
if valid != tt.valid || !equalInt64Pointers(got, tt.want) {
|
|
t.Fatalf("optionalNonNegativeInt64(%q) = %v,%v, want %v,%v", tt.input, got, valid, tt.want, tt.valid)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func int64Pointer(value int64) *int64 { return &value }
|
|
|
|
func equalInt64Pointers(left, right *int64) bool {
|
|
if left == nil || right == nil {
|
|
return left == right
|
|
}
|
|
return *left == *right
|
|
}
|