github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/api/server/form_test.go (about)

     1  package server
     2  
     3  import (
     4  	"net/http"
     5  	"net/url"
     6  	"testing"
     7  )
     8  
     9  func TestBoolValue(t *testing.T) {
    10  	cases := map[string]bool{
    11  		"":      false,
    12  		"0":     false,
    13  		"no":    false,
    14  		"false": false,
    15  		"none":  false,
    16  		"1":     true,
    17  		"yes":   true,
    18  		"true":  true,
    19  		"one":   true,
    20  		"100":   true,
    21  	}
    22  
    23  	for c, e := range cases {
    24  		v := url.Values{}
    25  		v.Set("test", c)
    26  		r, _ := http.NewRequest("POST", "", nil)
    27  		r.Form = v
    28  
    29  		a := boolValue(r, "test")
    30  		if a != e {
    31  			t.Fatalf("Value: %s, expected: %v, actual: %v", c, e, a)
    32  		}
    33  	}
    34  }
    35  
    36  func TestInt64ValueOrZero(t *testing.T) {
    37  	cases := map[string]int64{
    38  		"":     0,
    39  		"asdf": 0,
    40  		"0":    0,
    41  		"1":    1,
    42  	}
    43  
    44  	for c, e := range cases {
    45  		v := url.Values{}
    46  		v.Set("test", c)
    47  		r, _ := http.NewRequest("POST", "", nil)
    48  		r.Form = v
    49  
    50  		a := int64ValueOrZero(r, "test")
    51  		if a != e {
    52  			t.Fatalf("Value: %s, expected: %v, actual: %v", c, e, a)
    53  		}
    54  	}
    55  }