mirror of
				https://gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud
				synced 2025-11-04 11:01:46 +00:00 
			
		
		
		
	added gitlab-ci.yml and Makefile
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,6 +1,6 @@
 | 
				
			|||||||
# Created by .ignore support plugin (hsz.mobi)
 | 
					# Created by .ignore support plugin (hsz.mobi)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
config.yml
 | 
					config.yml-e
 | 
				
			||||||
### Go template
 | 
					### Go template
 | 
				
			||||||
# Binaries for programs and plugins
 | 
					# Binaries for programs and plugins
 | 
				
			||||||
*.exe
 | 
					*.exe
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										58
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					image: golang:alpine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					stages:
 | 
				
			||||||
 | 
					- test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					before_script:
 | 
				
			||||||
 | 
					- apk add --update git make
 | 
				
			||||||
 | 
					- go get -u github.com/kardianos/govendor
 | 
				
			||||||
 | 
					- mkdir -p /go/src/github.com/partitio
 | 
				
			||||||
 | 
					- cp -r $CI_PROJECT_DIR /go/src/github.com/partitio/gonextcloud
 | 
				
			||||||
 | 
					- cd /go/src/github.com/partitio/gonextcloud
 | 
				
			||||||
 | 
					- sed -i -e 's/$NEXTCLOUD_URL/'${NEXTCLOUD_URL//\//\\/}'/g' config.yml
 | 
				
			||||||
 | 
					- sed -i -e 's/$NEXTCLOUD_PASSWORD/'${NEXTCLOUD_PASSWORD}'/g' config.yml
 | 
				
			||||||
 | 
					- make dep
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					unit_tests:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  tags:
 | 
				
			||||||
 | 
					  - docker
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					  - make test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					race_detector:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  tags:
 | 
				
			||||||
 | 
					  - docker
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					  - make race
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					memory_sanitizer:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  tags:
 | 
				
			||||||
 | 
					  - docker
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					  - make msan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					code_coverage:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  tags:
 | 
				
			||||||
 | 
					  - docker
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					  - make coverage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					code_coverage_report:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  tags:
 | 
				
			||||||
 | 
					  - docker
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					  - make coverhtml
 | 
				
			||||||
 | 
					  only:
 | 
				
			||||||
 | 
					  - master
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					lint_code:
 | 
				
			||||||
 | 
					  stage: test
 | 
				
			||||||
 | 
					  tags:
 | 
				
			||||||
 | 
					  - docker
 | 
				
			||||||
 | 
					  script:
 | 
				
			||||||
 | 
					  - make lint
 | 
				
			||||||
							
								
								
									
										33
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					PROJECT_NAME := "gonextcloud"
 | 
				
			||||||
 | 
					PKG := "github.com/partitio/$(PROJECT_NAME)"
 | 
				
			||||||
 | 
					PKG_LIST := $(shell go list ${PKG})
 | 
				
			||||||
 | 
					GO_FILES := $(shell find . -name '*.go' | grep -v _test.go)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.PHONY: all dep build clean test coverage coverhtml lint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					all: build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					lint: ## Lint the files
 | 
				
			||||||
 | 
						@golint -set_exit_status ${PKG_LIST}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test: ## Run unittests
 | 
				
			||||||
 | 
						@go test ${PKG_LIST}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					race: dep ## Run data race detector
 | 
				
			||||||
 | 
						@go test -race ${PKG_LIST}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					msan: dep ## Run memory sanitizer
 | 
				
			||||||
 | 
						@go test -msan ${PKG_LIST}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					coverage: ## Generate global code coverage report
 | 
				
			||||||
 | 
						./tools/coverage.sh;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					coverhtml: ## Generate global code coverage report in HTML
 | 
				
			||||||
 | 
						./tools/coverage.sh html;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					dep: ## Get the dependencies
 | 
				
			||||||
 | 
						mkdir -p vendor
 | 
				
			||||||
 | 
						@govendor add +external
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					help: ## Display this help screen
 | 
				
			||||||
 | 
						@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
 | 
				
			||||||
							
								
								
									
										10
									
								
								config.ymle
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								config.ymle
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					url: $NEXTCLOUD_URL
 | 
				
			||||||
 | 
					login: admin
 | 
				
			||||||
 | 
					password: $NEXTCLOUD_PASSWORD
 | 
				
			||||||
 | 
					app-name: testapp
 | 
				
			||||||
 | 
					groups-to-create:
 | 
				
			||||||
 | 
					  - grp1
 | 
				
			||||||
 | 
					  - grp2
 | 
				
			||||||
 | 
					  - grp3
 | 
				
			||||||
 | 
					not-existing-user: this-user-should-not-exist
 | 
				
			||||||
 | 
					not-existing-group: this-group-should-not-exist
 | 
				
			||||||
							
								
								
									
										397
									
								
								vendor/github.com/fatih/structs/field_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										397
									
								
								vendor/github.com/fatih/structs/field_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,397 @@
 | 
				
			|||||||
 | 
					package structs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// A test struct that defines all cases
 | 
				
			||||||
 | 
					type Foo struct {
 | 
				
			||||||
 | 
						A    string
 | 
				
			||||||
 | 
						B    int    `structs:"y"`
 | 
				
			||||||
 | 
						C    bool   `json:"c"`
 | 
				
			||||||
 | 
						d    string // not exported
 | 
				
			||||||
 | 
						E    *Baz
 | 
				
			||||||
 | 
						x    string `xml:"x"` // not exported, with tag
 | 
				
			||||||
 | 
						Y    []string
 | 
				
			||||||
 | 
						Z    map[string]interface{}
 | 
				
			||||||
 | 
						*Bar // embedded
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Baz struct {
 | 
				
			||||||
 | 
						A string
 | 
				
			||||||
 | 
						B int
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Bar struct {
 | 
				
			||||||
 | 
						E string
 | 
				
			||||||
 | 
						F int
 | 
				
			||||||
 | 
						g []string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newStruct() *Struct {
 | 
				
			||||||
 | 
						b := &Bar{
 | 
				
			||||||
 | 
							E: "example",
 | 
				
			||||||
 | 
							F: 2,
 | 
				
			||||||
 | 
							g: []string{"zeynep", "fatih"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// B and x is not initialized for testing
 | 
				
			||||||
 | 
						f := &Foo{
 | 
				
			||||||
 | 
							A: "gopher",
 | 
				
			||||||
 | 
							C: true,
 | 
				
			||||||
 | 
							d: "small",
 | 
				
			||||||
 | 
							E: nil,
 | 
				
			||||||
 | 
							Y: []string{"example"},
 | 
				
			||||||
 | 
							Z: nil,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						f.Bar = b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return New(f)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Set(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f := s.Field("A")
 | 
				
			||||||
 | 
						err := f.Set("fatih")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if f.Value().(string) != "fatih" {
 | 
				
			||||||
 | 
							t.Errorf("Setted value is wrong: %s want: %s", f.Value().(string), "fatih")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("Y")
 | 
				
			||||||
 | 
						err = f.Set([]string{"override", "with", "this"})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sliceLen := len(f.Value().([]string))
 | 
				
			||||||
 | 
						if sliceLen != 3 {
 | 
				
			||||||
 | 
							t.Errorf("Setted values slice length is wrong: %d, want: %d", sliceLen, 3)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("C")
 | 
				
			||||||
 | 
						err = f.Set(false)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if f.Value().(bool) {
 | 
				
			||||||
 | 
							t.Errorf("Setted value is wrong: %t want: %t", f.Value().(bool), false)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// let's pass a different type
 | 
				
			||||||
 | 
						f = s.Field("A")
 | 
				
			||||||
 | 
						err = f.Set(123) // Field A is of type string, but we are going to pass an integer
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Setting a field's value with a different type than the field's type should return an error")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// old value should be still there :)
 | 
				
			||||||
 | 
						if f.Value().(string) != "fatih" {
 | 
				
			||||||
 | 
							t.Errorf("Setted value is wrong: %s want: %s", f.Value().(string), "fatih")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// let's access an unexported field, which should give an error
 | 
				
			||||||
 | 
						f = s.Field("d")
 | 
				
			||||||
 | 
						err = f.Set("large")
 | 
				
			||||||
 | 
						if err != errNotExported {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// let's set a pointer to struct
 | 
				
			||||||
 | 
						b := &Bar{
 | 
				
			||||||
 | 
							E: "gopher",
 | 
				
			||||||
 | 
							F: 2,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("Bar")
 | 
				
			||||||
 | 
						err = f.Set(b)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						baz := &Baz{
 | 
				
			||||||
 | 
							A: "helloWorld",
 | 
				
			||||||
 | 
							B: 42,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("E")
 | 
				
			||||||
 | 
						err = f.Set(baz)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ba := s.Field("E").Value().(*Baz)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ba.A != "helloWorld" {
 | 
				
			||||||
 | 
							t.Errorf("could not set baz. Got: %s Want: helloWorld", ba.A)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_NotSettable(t *testing.T) {
 | 
				
			||||||
 | 
						a := map[int]Baz{
 | 
				
			||||||
 | 
							4: {
 | 
				
			||||||
 | 
								A: "value",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := New(a[4])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := s.Field("A").Set("newValue"); err != errNotSettable {
 | 
				
			||||||
 | 
							t.Errorf("Trying to set non-settable field should error with %q. Got %q instead.", errNotSettable, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Zero(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f := s.Field("A")
 | 
				
			||||||
 | 
						err := f.Zero()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if f.Value().(string) != "" {
 | 
				
			||||||
 | 
							t.Errorf("Zeroed value is wrong: %s want: %s", f.Value().(string), "")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("Y")
 | 
				
			||||||
 | 
						err = f.Zero()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sliceLen := len(f.Value().([]string))
 | 
				
			||||||
 | 
						if sliceLen != 0 {
 | 
				
			||||||
 | 
							t.Errorf("Zeroed values slice length is wrong: %d, want: %d", sliceLen, 0)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("C")
 | 
				
			||||||
 | 
						err = f.Zero()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if f.Value().(bool) {
 | 
				
			||||||
 | 
							t.Errorf("Zeroed value is wrong: %t want: %t", f.Value().(bool), false)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// let's access an unexported field, which should give an error
 | 
				
			||||||
 | 
						f = s.Field("d")
 | 
				
			||||||
 | 
						err = f.Zero()
 | 
				
			||||||
 | 
						if err != errNotExported {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("Bar")
 | 
				
			||||||
 | 
						err = f.Zero()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("E")
 | 
				
			||||||
 | 
						err = f.Zero()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v := s.Field("E").value
 | 
				
			||||||
 | 
						if !v.IsNil() {
 | 
				
			||||||
 | 
							t.Errorf("could not set baz. Got: %s Want: <nil>", v.Interface())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							err := recover()
 | 
				
			||||||
 | 
							if err == nil {
 | 
				
			||||||
 | 
								t.Error("Retrieveing a non existing field from the struct should panic")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ = s.Field("no-field")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Kind(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f := s.Field("A")
 | 
				
			||||||
 | 
						if f.Kind() != reflect.String {
 | 
				
			||||||
 | 
							t.Errorf("Field A has wrong kind: %s want: %s", f.Kind(), reflect.String)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						f = s.Field("B")
 | 
				
			||||||
 | 
						if f.Kind() != reflect.Int {
 | 
				
			||||||
 | 
							t.Errorf("Field B has wrong kind: %s want: %s", f.Kind(), reflect.Int)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// unexported
 | 
				
			||||||
 | 
						f = s.Field("d")
 | 
				
			||||||
 | 
						if f.Kind() != reflect.String {
 | 
				
			||||||
 | 
							t.Errorf("Field d has wrong kind: %s want: %s", f.Kind(), reflect.String)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Tag(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v := s.Field("B").Tag("json")
 | 
				
			||||||
 | 
						if v != "" {
 | 
				
			||||||
 | 
							t.Errorf("Field's tag value of a non existing tag should return empty, got: %s", v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v = s.Field("C").Tag("json")
 | 
				
			||||||
 | 
						if v != "c" {
 | 
				
			||||||
 | 
							t.Errorf("Field's tag value of the existing field C should return 'c', got: %s", v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v = s.Field("d").Tag("json")
 | 
				
			||||||
 | 
						if v != "" {
 | 
				
			||||||
 | 
							t.Errorf("Field's tag value of a non exported field should return empty, got: %s", v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v = s.Field("x").Tag("xml")
 | 
				
			||||||
 | 
						if v != "x" {
 | 
				
			||||||
 | 
							t.Errorf("Field's tag value of a non exported field with a tag should return 'x', got: %s", v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v = s.Field("A").Tag("json")
 | 
				
			||||||
 | 
						if v != "" {
 | 
				
			||||||
 | 
							t.Errorf("Field's tag value of a existing field without a tag should return empty, got: %s", v)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Value(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v := s.Field("A").Value()
 | 
				
			||||||
 | 
						val, ok := v.(string)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							t.Errorf("Field's value of a A should be string")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if val != "gopher" {
 | 
				
			||||||
 | 
							t.Errorf("Field's value of a existing tag should return 'gopher', got: %s", val)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							err := recover()
 | 
				
			||||||
 | 
							if err == nil {
 | 
				
			||||||
 | 
								t.Error("Value of a non exported field from the field should panic")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// should panic
 | 
				
			||||||
 | 
						_ = s.Field("d").Value()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_IsEmbedded(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !s.Field("Bar").IsEmbedded() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'Bar' field is an embedded field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if s.Field("d").IsEmbedded() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'd' field is not an embedded field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_IsExported(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !s.Field("Bar").IsExported() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'Bar' field is an exported field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !s.Field("A").IsExported() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'A' field is an exported field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if s.Field("d").IsExported() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'd' field is not an exported field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_IsZero(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if s.Field("A").IsZero() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'A' field is an initialized field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !s.Field("B").IsZero() {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'B' field is not an initialized field")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Name(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if s.Field("A").Name() != "A" {
 | 
				
			||||||
 | 
							t.Errorf("Fields 'A' field should have the name 'A'")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Field(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						e := s.Field("Bar").Field("E")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						val, ok := e.Value().(string)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							t.Error("The value of the field 'e' inside 'Bar' struct should be string")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if val != "example" {
 | 
				
			||||||
 | 
							t.Errorf("The value of 'e' should be 'example, got: %s", val)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer func() {
 | 
				
			||||||
 | 
							err := recover()
 | 
				
			||||||
 | 
							if err == nil {
 | 
				
			||||||
 | 
								t.Error("Field of a non existing nested struct should panic")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_ = s.Field("Bar").Field("e")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_Fields(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
						fields := s.Field("Bar").Fields()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(fields) != 3 {
 | 
				
			||||||
 | 
							t.Errorf("We expect 3 fields in embedded struct, was: %d", len(fields))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestField_FieldOk(t *testing.T) {
 | 
				
			||||||
 | 
						s := newStruct()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						b, ok := s.FieldOk("Bar")
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							t.Error("The field 'Bar' should exists.")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						e, ok := b.FieldOk("E")
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							t.Error("The field 'E' should exists.")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						val, ok := e.Value().(string)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							t.Error("The value of the field 'e' inside 'Bar' struct should be string")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if val != "example" {
 | 
				
			||||||
 | 
							t.Errorf("The value of 'e' should be 'example, got: %s", val)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										351
									
								
								vendor/github.com/fatih/structs/structs_example_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										351
									
								
								vendor/github.com/fatih/structs/structs_example_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,351 @@
 | 
				
			|||||||
 | 
					package structs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleNew() {
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name    string
 | 
				
			||||||
 | 
							ID      int32
 | 
				
			||||||
 | 
							Enabled bool
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						server := &Server{
 | 
				
			||||||
 | 
							Name:    "Arslan",
 | 
				
			||||||
 | 
							ID:      123456,
 | 
				
			||||||
 | 
							Enabled: true,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := New(server)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Name        : %v\n", s.Name())
 | 
				
			||||||
 | 
						fmt.Printf("Values      : %v\n", s.Values())
 | 
				
			||||||
 | 
						fmt.Printf("Value of ID : %v\n", s.Field("ID").Value())
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Name        : Server
 | 
				
			||||||
 | 
						// Values      : [Arslan 123456 true]
 | 
				
			||||||
 | 
						// Value of ID : 123456
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleMap() {
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name    string
 | 
				
			||||||
 | 
							ID      int32
 | 
				
			||||||
 | 
							Enabled bool
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Name:    "Arslan",
 | 
				
			||||||
 | 
							ID:      123456,
 | 
				
			||||||
 | 
							Enabled: true,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := Map(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", m["Name"])
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", m["ID"])
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", m["Enabled"])
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// "Arslan"
 | 
				
			||||||
 | 
						// 123456
 | 
				
			||||||
 | 
						// true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleMap_tags() {
 | 
				
			||||||
 | 
						// Custom tags can change the map keys instead of using the fields name
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name    string `structs:"server_name"`
 | 
				
			||||||
 | 
							ID      int32  `structs:"server_id"`
 | 
				
			||||||
 | 
							Enabled bool   `structs:"enabled"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Name: "Zeynep",
 | 
				
			||||||
 | 
							ID:   789012,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := Map(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// access them by the custom tags defined above
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", m["server_name"])
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", m["server_id"])
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", m["enabled"])
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// "Zeynep"
 | 
				
			||||||
 | 
						// 789012
 | 
				
			||||||
 | 
						// false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleMap_omitNested() {
 | 
				
			||||||
 | 
						// By default field with struct types are processed too. We can stop
 | 
				
			||||||
 | 
						// processing them via "omitnested" tag option.
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name string    `structs:"server_name"`
 | 
				
			||||||
 | 
							ID   int32     `structs:"server_id"`
 | 
				
			||||||
 | 
							Time time.Time `structs:"time,omitnested"` // do not convert to map[string]interface{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const shortForm = "2006-Jan-02"
 | 
				
			||||||
 | 
						t, _ := time.Parse("2006-Jan-02", "2013-Feb-03")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Name: "Zeynep",
 | 
				
			||||||
 | 
							ID:   789012,
 | 
				
			||||||
 | 
							Time: t,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := Map(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// access them by the custom tags defined above
 | 
				
			||||||
 | 
						fmt.Printf("%v\n", m["server_name"])
 | 
				
			||||||
 | 
						fmt.Printf("%v\n", m["server_id"])
 | 
				
			||||||
 | 
						fmt.Printf("%v\n", m["time"].(time.Time))
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Zeynep
 | 
				
			||||||
 | 
						// 789012
 | 
				
			||||||
 | 
						// 2013-02-03 00:00:00 +0000 UTC
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleMap_omitEmpty() {
 | 
				
			||||||
 | 
						// By default field with struct types of zero values are processed too. We
 | 
				
			||||||
 | 
						// can stop processing them via "omitempty" tag option.
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name     string `structs:",omitempty"`
 | 
				
			||||||
 | 
							ID       int32  `structs:"server_id,omitempty"`
 | 
				
			||||||
 | 
							Location string
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Only add location
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Location: "Tokyo",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := Map(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// map contains only the Location field
 | 
				
			||||||
 | 
						fmt.Printf("%v\n", m)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// map[Location:Tokyo]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleValues() {
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name    string
 | 
				
			||||||
 | 
							ID      int32
 | 
				
			||||||
 | 
							Enabled bool
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Name:    "Fatih",
 | 
				
			||||||
 | 
							ID:      135790,
 | 
				
			||||||
 | 
							Enabled: false,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := Values(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Values: %+v\n", m)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Values: [Fatih 135790 false]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleValues_omitEmpty() {
 | 
				
			||||||
 | 
						// By default field with struct types of zero values are processed too. We
 | 
				
			||||||
 | 
						// can stop processing them via "omitempty" tag option.
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name     string `structs:",omitempty"`
 | 
				
			||||||
 | 
							ID       int32  `structs:"server_id,omitempty"`
 | 
				
			||||||
 | 
							Location string
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Only add location
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Location: "Ankara",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := Values(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// values contains only the Location field
 | 
				
			||||||
 | 
						fmt.Printf("Values: %+v\n", m)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Values: [Ankara]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleValues_tags() {
 | 
				
			||||||
 | 
						type Location struct {
 | 
				
			||||||
 | 
							City    string
 | 
				
			||||||
 | 
							Country string
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name     string
 | 
				
			||||||
 | 
							ID       int32
 | 
				
			||||||
 | 
							Enabled  bool
 | 
				
			||||||
 | 
							Location Location `structs:"-"` // values from location are not included anymore
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Server{
 | 
				
			||||||
 | 
							Name:     "Fatih",
 | 
				
			||||||
 | 
							ID:       135790,
 | 
				
			||||||
 | 
							Enabled:  false,
 | 
				
			||||||
 | 
							Location: Location{City: "Ankara", Country: "Turkey"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Let get all values from the struct s. Note that we don't include values
 | 
				
			||||||
 | 
						// from the Location field
 | 
				
			||||||
 | 
						m := Values(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Values: %+v\n", m)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Values: [Fatih 135790 false]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleFields() {
 | 
				
			||||||
 | 
						type Access struct {
 | 
				
			||||||
 | 
							Name         string
 | 
				
			||||||
 | 
							LastAccessed time.Time
 | 
				
			||||||
 | 
							Number       int
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Access{
 | 
				
			||||||
 | 
							Name:         "Fatih",
 | 
				
			||||||
 | 
							LastAccessed: time.Now(),
 | 
				
			||||||
 | 
							Number:       1234567,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fields := Fields(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i, field := range fields {
 | 
				
			||||||
 | 
							fmt.Printf("[%d] %+v\n", i, field.Name())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// [0] Name
 | 
				
			||||||
 | 
						// [1] LastAccessed
 | 
				
			||||||
 | 
						// [2] Number
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleFields_nested() {
 | 
				
			||||||
 | 
						type Person struct {
 | 
				
			||||||
 | 
							Name   string
 | 
				
			||||||
 | 
							Number int
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						type Access struct {
 | 
				
			||||||
 | 
							Person        Person
 | 
				
			||||||
 | 
							HasPermission bool
 | 
				
			||||||
 | 
							LastAccessed  time.Time
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						s := &Access{
 | 
				
			||||||
 | 
							Person:        Person{Name: "fatih", Number: 1234567},
 | 
				
			||||||
 | 
							LastAccessed:  time.Now(),
 | 
				
			||||||
 | 
							HasPermission: true,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Let's get all fields from the struct s.
 | 
				
			||||||
 | 
						fields := Fields(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, field := range fields {
 | 
				
			||||||
 | 
							if field.Name() == "Person" {
 | 
				
			||||||
 | 
								fmt.Printf("Access.Person.Name: %+v\n", field.Field("Name").Value())
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Access.Person.Name: fatih
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleField() {
 | 
				
			||||||
 | 
						type Person struct {
 | 
				
			||||||
 | 
							Name   string
 | 
				
			||||||
 | 
							Number int
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						type Access struct {
 | 
				
			||||||
 | 
							Person        Person
 | 
				
			||||||
 | 
							HasPermission bool
 | 
				
			||||||
 | 
							LastAccessed  time.Time
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						access := &Access{
 | 
				
			||||||
 | 
							Person:        Person{Name: "fatih", Number: 1234567},
 | 
				
			||||||
 | 
							LastAccessed:  time.Now(),
 | 
				
			||||||
 | 
							HasPermission: true,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Create a new Struct type
 | 
				
			||||||
 | 
						s := New(access)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get the Field type for "Person" field
 | 
				
			||||||
 | 
						p := s.Field("Person")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Get the underlying "Name field" and print the value of it
 | 
				
			||||||
 | 
						name := p.Field("Name")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("Value of Person.Access.Name: %+v\n", name.Value())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// Value of Person.Access.Name: fatih
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleIsZero() {
 | 
				
			||||||
 | 
						type Server struct {
 | 
				
			||||||
 | 
							Name    string
 | 
				
			||||||
 | 
							ID      int32
 | 
				
			||||||
 | 
							Enabled bool
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Nothing is initialized
 | 
				
			||||||
 | 
						a := &Server{}
 | 
				
			||||||
 | 
						isZeroA := IsZero(a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Name and Enabled is initialized, but not ID
 | 
				
			||||||
 | 
						b := &Server{
 | 
				
			||||||
 | 
							Name:    "Golang",
 | 
				
			||||||
 | 
							Enabled: true,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						isZeroB := IsZero(b)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", isZeroA)
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", isZeroB)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// true
 | 
				
			||||||
 | 
						// false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleHasZero() {
 | 
				
			||||||
 | 
						// Let's define an Access struct. Note that the "Enabled" field is not
 | 
				
			||||||
 | 
						// going to be checked because we added the "structs" tag to the field.
 | 
				
			||||||
 | 
						type Access struct {
 | 
				
			||||||
 | 
							Name         string
 | 
				
			||||||
 | 
							LastAccessed time.Time
 | 
				
			||||||
 | 
							Number       int
 | 
				
			||||||
 | 
							Enabled      bool `structs:"-"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Name and Number is not initialized.
 | 
				
			||||||
 | 
						a := &Access{
 | 
				
			||||||
 | 
							LastAccessed: time.Now(),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						hasZeroA := HasZero(a)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Name and Number is initialized.
 | 
				
			||||||
 | 
						b := &Access{
 | 
				
			||||||
 | 
							Name:         "Fatih",
 | 
				
			||||||
 | 
							LastAccessed: time.Now(),
 | 
				
			||||||
 | 
							Number:       12345,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						hasZeroB := HasZero(b)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", hasZeroA)
 | 
				
			||||||
 | 
						fmt.Printf("%#v\n", hasZeroB)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// true
 | 
				
			||||||
 | 
						// false
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1453
									
								
								vendor/github.com/fatih/structs/structs_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1453
									
								
								vendor/github.com/fatih/structs/structs_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										46
									
								
								vendor/github.com/fatih/structs/tags_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								vendor/github.com/fatih/structs/tags_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					package structs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestParseTag_Name(t *testing.T) {
 | 
				
			||||||
 | 
						tags := []struct {
 | 
				
			||||||
 | 
							tag string
 | 
				
			||||||
 | 
							has bool
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{"", false},
 | 
				
			||||||
 | 
							{"name", true},
 | 
				
			||||||
 | 
							{"name,opt", true},
 | 
				
			||||||
 | 
							{"name , opt, opt2", false}, // has a single whitespace
 | 
				
			||||||
 | 
							{", opt, opt2", false},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tag := range tags {
 | 
				
			||||||
 | 
							name, _ := parseTag(tag.tag)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (name != "name") && tag.has {
 | 
				
			||||||
 | 
								t.Errorf("Parse tag should return name: %#v", tag)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestParseTag_Opts(t *testing.T) {
 | 
				
			||||||
 | 
						tags := []struct {
 | 
				
			||||||
 | 
							opts string
 | 
				
			||||||
 | 
							has  bool
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{"name", false},
 | 
				
			||||||
 | 
							{"name,opt", true},
 | 
				
			||||||
 | 
							{"name , opt, opt2", false}, // has a single whitespace
 | 
				
			||||||
 | 
							{",opt, opt2", true},
 | 
				
			||||||
 | 
							{", opt3, opt4", false},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// search for "opt"
 | 
				
			||||||
 | 
						for _, tag := range tags {
 | 
				
			||||||
 | 
							_, opts := parseTag(tag.opts)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if opts.Has("opt") != tag.has {
 | 
				
			||||||
 | 
								t.Errorf("Tag opts should have opt: %#v", tag)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										328
									
								
								vendor/github.com/google/go-querystring/query/encode_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										328
									
								
								vendor/github.com/google/go-querystring/query/encode_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,328 @@
 | 
				
			|||||||
 | 
					// Copyright 2013 The Go Authors. All rights reserved.
 | 
				
			||||||
 | 
					// Use of this source code is governed by a BSD-style
 | 
				
			||||||
 | 
					// license that can be found in the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package query
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"reflect"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Nested struct {
 | 
				
			||||||
 | 
						A   SubNested  `url:"a"`
 | 
				
			||||||
 | 
						B   *SubNested `url:"b"`
 | 
				
			||||||
 | 
						Ptr *SubNested `url:"ptr,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type SubNested struct {
 | 
				
			||||||
 | 
						Value string `url:"value"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValues_types(t *testing.T) {
 | 
				
			||||||
 | 
						str := "string"
 | 
				
			||||||
 | 
						strPtr := &str
 | 
				
			||||||
 | 
						timeVal := time.Date(2000, 1, 1, 12, 34, 56, 0, time.UTC)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							in   interface{}
 | 
				
			||||||
 | 
							want url.Values
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// basic primitives
 | 
				
			||||||
 | 
								struct {
 | 
				
			||||||
 | 
									A string
 | 
				
			||||||
 | 
									B int
 | 
				
			||||||
 | 
									C uint
 | 
				
			||||||
 | 
									D float32
 | 
				
			||||||
 | 
									E bool
 | 
				
			||||||
 | 
								}{},
 | 
				
			||||||
 | 
								url.Values{
 | 
				
			||||||
 | 
									"A": {""},
 | 
				
			||||||
 | 
									"B": {"0"},
 | 
				
			||||||
 | 
									"C": {"0"},
 | 
				
			||||||
 | 
									"D": {"0"},
 | 
				
			||||||
 | 
									"E": {"false"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// pointers
 | 
				
			||||||
 | 
								struct {
 | 
				
			||||||
 | 
									A *string
 | 
				
			||||||
 | 
									B *int
 | 
				
			||||||
 | 
									C **string
 | 
				
			||||||
 | 
									D *time.Time
 | 
				
			||||||
 | 
								}{
 | 
				
			||||||
 | 
									A: strPtr,
 | 
				
			||||||
 | 
									C: &strPtr,
 | 
				
			||||||
 | 
									D: &timeVal,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								url.Values{
 | 
				
			||||||
 | 
									"A": {str},
 | 
				
			||||||
 | 
									"B": {""},
 | 
				
			||||||
 | 
									"C": {str},
 | 
				
			||||||
 | 
									"D": {"2000-01-01T12:34:56Z"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// slices and arrays
 | 
				
			||||||
 | 
								struct {
 | 
				
			||||||
 | 
									A []string
 | 
				
			||||||
 | 
									B []string `url:",comma"`
 | 
				
			||||||
 | 
									C []string `url:",space"`
 | 
				
			||||||
 | 
									D [2]string
 | 
				
			||||||
 | 
									E [2]string `url:",comma"`
 | 
				
			||||||
 | 
									F [2]string `url:",space"`
 | 
				
			||||||
 | 
									G []*string `url:",space"`
 | 
				
			||||||
 | 
									H []bool    `url:",int,space"`
 | 
				
			||||||
 | 
									I []string  `url:",brackets"`
 | 
				
			||||||
 | 
									J []string  `url:",semicolon"`
 | 
				
			||||||
 | 
									K []string  `url:",numbered"`
 | 
				
			||||||
 | 
								}{
 | 
				
			||||||
 | 
									A: []string{"a", "b"},
 | 
				
			||||||
 | 
									B: []string{"a", "b"},
 | 
				
			||||||
 | 
									C: []string{"a", "b"},
 | 
				
			||||||
 | 
									D: [2]string{"a", "b"},
 | 
				
			||||||
 | 
									E: [2]string{"a", "b"},
 | 
				
			||||||
 | 
									F: [2]string{"a", "b"},
 | 
				
			||||||
 | 
									G: []*string{&str, &str},
 | 
				
			||||||
 | 
									H: []bool{true, false},
 | 
				
			||||||
 | 
									I: []string{"a", "b"},
 | 
				
			||||||
 | 
									J: []string{"a", "b"},
 | 
				
			||||||
 | 
									K: []string{"a", "b"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								url.Values{
 | 
				
			||||||
 | 
									"A":   {"a", "b"},
 | 
				
			||||||
 | 
									"B":   {"a,b"},
 | 
				
			||||||
 | 
									"C":   {"a b"},
 | 
				
			||||||
 | 
									"D":   {"a", "b"},
 | 
				
			||||||
 | 
									"E":   {"a,b"},
 | 
				
			||||||
 | 
									"F":   {"a b"},
 | 
				
			||||||
 | 
									"G":   {"string string"},
 | 
				
			||||||
 | 
									"H":   {"1 0"},
 | 
				
			||||||
 | 
									"I[]": {"a", "b"},
 | 
				
			||||||
 | 
									"J":   {"a;b"},
 | 
				
			||||||
 | 
									"K0":  {"a"},
 | 
				
			||||||
 | 
									"K1":  {"b"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// other types
 | 
				
			||||||
 | 
								struct {
 | 
				
			||||||
 | 
									A time.Time
 | 
				
			||||||
 | 
									B time.Time `url:",unix"`
 | 
				
			||||||
 | 
									C bool      `url:",int"`
 | 
				
			||||||
 | 
									D bool      `url:",int"`
 | 
				
			||||||
 | 
								}{
 | 
				
			||||||
 | 
									A: time.Date(2000, 1, 1, 12, 34, 56, 0, time.UTC),
 | 
				
			||||||
 | 
									B: time.Date(2000, 1, 1, 12, 34, 56, 0, time.UTC),
 | 
				
			||||||
 | 
									C: true,
 | 
				
			||||||
 | 
									D: false,
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								url.Values{
 | 
				
			||||||
 | 
									"A": {"2000-01-01T12:34:56Z"},
 | 
				
			||||||
 | 
									"B": {"946730096"},
 | 
				
			||||||
 | 
									"C": {"1"},
 | 
				
			||||||
 | 
									"D": {"0"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								struct {
 | 
				
			||||||
 | 
									Nest Nested `url:"nest"`
 | 
				
			||||||
 | 
								}{
 | 
				
			||||||
 | 
									Nested{
 | 
				
			||||||
 | 
										A: SubNested{
 | 
				
			||||||
 | 
											Value: "that",
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								url.Values{
 | 
				
			||||||
 | 
									"nest[a][value]": {"that"},
 | 
				
			||||||
 | 
									"nest[b]":        {""},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								struct {
 | 
				
			||||||
 | 
									Nest Nested `url:"nest"`
 | 
				
			||||||
 | 
								}{
 | 
				
			||||||
 | 
									Nested{
 | 
				
			||||||
 | 
										Ptr: &SubNested{
 | 
				
			||||||
 | 
											Value: "that",
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								url.Values{
 | 
				
			||||||
 | 
									"nest[a][value]":   {""},
 | 
				
			||||||
 | 
									"nest[b]":          {""},
 | 
				
			||||||
 | 
									"nest[ptr][value]": {"that"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								nil,
 | 
				
			||||||
 | 
								url.Values{},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i, tt := range tests {
 | 
				
			||||||
 | 
							v, err := Values(tt.in)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("%d. Values(%q) returned error: %v", i, tt.in, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !reflect.DeepEqual(tt.want, v) {
 | 
				
			||||||
 | 
								t.Errorf("%d. Values(%q) returned %v, want %v", i, tt.in, v, tt.want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValues_omitEmpty(t *testing.T) {
 | 
				
			||||||
 | 
						str := ""
 | 
				
			||||||
 | 
						s := struct {
 | 
				
			||||||
 | 
							a string
 | 
				
			||||||
 | 
							A string
 | 
				
			||||||
 | 
							B string  `url:",omitempty"`
 | 
				
			||||||
 | 
							C string  `url:"-"`
 | 
				
			||||||
 | 
							D string  `url:"omitempty"` // actually named omitempty, not an option
 | 
				
			||||||
 | 
							E *string `url:",omitempty"`
 | 
				
			||||||
 | 
						}{E: &str}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						v, err := Values(s)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Values(%q) returned error: %v", s, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						want := url.Values{
 | 
				
			||||||
 | 
							"A":         {""},
 | 
				
			||||||
 | 
							"omitempty": {""},
 | 
				
			||||||
 | 
							"E":         {""}, // E is included because the pointer is not empty, even though the string being pointed to is
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !reflect.DeepEqual(want, v) {
 | 
				
			||||||
 | 
							t.Errorf("Values(%q) returned %v, want %v", s, v, want)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type A struct {
 | 
				
			||||||
 | 
						B
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type B struct {
 | 
				
			||||||
 | 
						C string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type D struct {
 | 
				
			||||||
 | 
						B
 | 
				
			||||||
 | 
						C string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type e struct {
 | 
				
			||||||
 | 
						B
 | 
				
			||||||
 | 
						C string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type F struct {
 | 
				
			||||||
 | 
						e
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValues_embeddedStructs(t *testing.T) {
 | 
				
			||||||
 | 
						tests := []struct {
 | 
				
			||||||
 | 
							in   interface{}
 | 
				
			||||||
 | 
							want url.Values
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								A{B{C: "foo"}},
 | 
				
			||||||
 | 
								url.Values{"C": {"foo"}},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								D{B: B{C: "bar"}, C: "foo"},
 | 
				
			||||||
 | 
								url.Values{"C": {"foo", "bar"}},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								F{e{B: B{C: "bar"}, C: "foo"}}, // With unexported embed
 | 
				
			||||||
 | 
								url.Values{"C": {"foo", "bar"}},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i, tt := range tests {
 | 
				
			||||||
 | 
							v, err := Values(tt.in)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								t.Errorf("%d. Values(%q) returned error: %v", i, tt.in, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !reflect.DeepEqual(tt.want, v) {
 | 
				
			||||||
 | 
								t.Errorf("%d. Values(%q) returned %v, want %v", i, tt.in, v, tt.want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValues_invalidInput(t *testing.T) {
 | 
				
			||||||
 | 
						_, err := Values("")
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Errorf("expected Values() to return an error on invalid input")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type EncodedArgs []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m EncodedArgs) EncodeValues(key string, v *url.Values) error {
 | 
				
			||||||
 | 
						for i, arg := range m {
 | 
				
			||||||
 | 
							v.Set(fmt.Sprintf("%s.%d", key, i), arg)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValues_Marshaler(t *testing.T) {
 | 
				
			||||||
 | 
						s := struct {
 | 
				
			||||||
 | 
							Args EncodedArgs `url:"arg"`
 | 
				
			||||||
 | 
						}{[]string{"a", "b", "c"}}
 | 
				
			||||||
 | 
						v, err := Values(s)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Values(%q) returned error: %v", s, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						want := url.Values{
 | 
				
			||||||
 | 
							"arg.0": {"a"},
 | 
				
			||||||
 | 
							"arg.1": {"b"},
 | 
				
			||||||
 | 
							"arg.2": {"c"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !reflect.DeepEqual(want, v) {
 | 
				
			||||||
 | 
							t.Errorf("Values(%q) returned %v, want %v", s, v, want)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValues_MarshalerWithNilPointer(t *testing.T) {
 | 
				
			||||||
 | 
						s := struct {
 | 
				
			||||||
 | 
							Args *EncodedArgs `url:"arg"`
 | 
				
			||||||
 | 
						}{}
 | 
				
			||||||
 | 
						v, err := Values(s)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("Values(%q) returned error: %v", s, err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						want := url.Values{}
 | 
				
			||||||
 | 
						if !reflect.DeepEqual(want, v) {
 | 
				
			||||||
 | 
							t.Errorf("Values(%q) returned %v, want %v", s, v, want)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTagParsing(t *testing.T) {
 | 
				
			||||||
 | 
						name, opts := parseTag("field,foobar,foo")
 | 
				
			||||||
 | 
						if name != "field" {
 | 
				
			||||||
 | 
							t.Fatalf("name = %q, want field", name)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, tt := range []struct {
 | 
				
			||||||
 | 
							opt  string
 | 
				
			||||||
 | 
							want bool
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{"foobar", true},
 | 
				
			||||||
 | 
							{"foo", true},
 | 
				
			||||||
 | 
							{"bar", false},
 | 
				
			||||||
 | 
							{"field", false},
 | 
				
			||||||
 | 
						} {
 | 
				
			||||||
 | 
							if opts.Contains(tt.opt) != tt.want {
 | 
				
			||||||
 | 
								t.Errorf("Contains(%q) = %v", tt.opt, !tt.want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										99
									
								
								vendor/github.com/levigross/grequests/base_delete_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								vendor/github.com/levigross/grequests/base_delete_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicDeleteRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Delete("http://httpbin.org/delete", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestDeleteSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Delete("http://httpbin.org/delete", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cookieURL, err := url.Parse("http://httpbin.org")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("We (for some reason) cannot parse the cookie URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
 | 
				
			||||||
 | 
							t.Error("Invalid number of cookies provided: ", resp.RawResponse.Cookies())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
 | 
				
			||||||
 | 
							switch cookie.Name {
 | 
				
			||||||
 | 
							case "one":
 | 
				
			||||||
 | 
								if cookie.Value != "two" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "two":
 | 
				
			||||||
 | 
								if cookie.Value != "three" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "three":
 | 
				
			||||||
 | 
								if cookie.Value != "four" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								t.Error("We should not have any other cookies: ", cookie)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestDeleteInvalidURLSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Delete("%../dir/", nil); err == nil {
 | 
				
			||||||
 | 
							t.Error("Some how the request was valid to make request ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1286
									
								
								vendor/github.com/levigross/grequests/base_get_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1286
									
								
								vendor/github.com/levigross/grequests/base_get_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										115
									
								
								vendor/github.com/levigross/grequests/base_head_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								vendor/github.com/levigross/grequests/base_head_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,115 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicHeadRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Head("http://httpbin.org/get", nil)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make HEAD request: ", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("HEAD request did not return success: ", resp.StatusCode)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Header.Get("Content-Type") != "application/json" {
 | 
				
			||||||
 | 
							t.Error("Content Type Header is unexpected: ", resp.Header.Get("Content-Type"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicHeadRequestNoContent(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Head("http://httpbin.org/bytes/0", nil)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make HEAD request: ", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("HEAD request did not return success: ", resp.StatusCode)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Header.Get("Content-Type") != "application/octet-stream" {
 | 
				
			||||||
 | 
							t.Error("Content Type Header is unexpected: ", resp.Header.Get("Content-Type"))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("Somehow byte buffer is working now (bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("Somehow byte buffer is working now (bytes)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHeadSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Head("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Head("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Head("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cookieURL, err := url.Parse("http://httpbin.org")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("We (for some reason) cannot parse the cookie URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
 | 
				
			||||||
 | 
							t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
 | 
				
			||||||
 | 
							switch cookie.Name {
 | 
				
			||||||
 | 
							case "one":
 | 
				
			||||||
 | 
								if cookie.Value != "two" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "two":
 | 
				
			||||||
 | 
								if cookie.Value != "three" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "three":
 | 
				
			||||||
 | 
								if cookie.Value != "four" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								t.Error("We should not have any other cookies: ", cookie)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHeadInvalidURLSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Head("%../dir/", nil); err == nil {
 | 
				
			||||||
 | 
							t.Error("Some how the request was valid to make request ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										88
									
								
								vendor/github.com/levigross/grequests/base_options_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								vendor/github.com/levigross/grequests/base_options_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicOPTIONSRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Options("http://httpbin.org/get", nil)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make OPTIONS request: ", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Options request did not return success: ", resp.StatusCode)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Header.Get("Access-Control-Allow-Methods") != "GET, POST, PUT, DELETE, PATCH, OPTIONS" {
 | 
				
			||||||
 | 
							t.Error("Access-Control-Allow-Methods Type Header is unexpected: ", resp.Header)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestOptionsSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Options("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Options("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Options("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cookieURL, err := url.Parse("http://httpbin.org")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("We (for some reason) cannot parse the cookie URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
 | 
				
			||||||
 | 
							switch cookie.Name {
 | 
				
			||||||
 | 
							case "one":
 | 
				
			||||||
 | 
								if cookie.Value != "two" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "two":
 | 
				
			||||||
 | 
								if cookie.Value != "three" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "three":
 | 
				
			||||||
 | 
								if cookie.Value != "four" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								t.Error("We should not have any other cookies: ", cookie)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestOptionsInvalidURLSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Options("%../dir/", nil); err == nil {
 | 
				
			||||||
 | 
							t.Error("Some how the request was valid to make request ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										99
									
								
								vendor/github.com/levigross/grequests/base_patch_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								vendor/github.com/levigross/grequests/base_patch_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,99 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPatchRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Patch("http://httpbin.org/patch", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPatchSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Patch("http://httpbin.org/patch", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK: ", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cookieURL, err := url.Parse("http://httpbin.org")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("We (for some reason) cannot parse the cookie URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
 | 
				
			||||||
 | 
							t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
 | 
				
			||||||
 | 
							switch cookie.Name {
 | 
				
			||||||
 | 
							case "one":
 | 
				
			||||||
 | 
								if cookie.Value != "two" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "two":
 | 
				
			||||||
 | 
								if cookie.Value != "three" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "three":
 | 
				
			||||||
 | 
								if cookie.Value != "four" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								t.Error("We should not have any other cookies: ", cookie)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPatchInvalidURLSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Patch("%../dir/", nil); err == nil {
 | 
				
			||||||
 | 
							t.Error("Some how the request was valid to make request ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										948
									
								
								vendor/github.com/levigross/grequests/base_post_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										948
									
								
								vendor/github.com/levigross/grequests/base_post_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,948 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"encoding/xml"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"math"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BasicPostResponse struct {
 | 
				
			||||||
 | 
						Args  struct{} `json:"args"`
 | 
				
			||||||
 | 
						Data  string   `json:"data"`
 | 
				
			||||||
 | 
						Files struct{} `json:"files"`
 | 
				
			||||||
 | 
						Form  struct {
 | 
				
			||||||
 | 
							One string `json:"one"`
 | 
				
			||||||
 | 
						} `json:"form"`
 | 
				
			||||||
 | 
						Headers struct {
 | 
				
			||||||
 | 
							Accept        string `json:"Accept"`
 | 
				
			||||||
 | 
							ContentLength string `json:"Content-Length"`
 | 
				
			||||||
 | 
							ContentType   string `json:"Content-Type"`
 | 
				
			||||||
 | 
							Host          string `json:"Host"`
 | 
				
			||||||
 | 
							UserAgent     string `json:"User-Agent"`
 | 
				
			||||||
 | 
						} `json:"headers"`
 | 
				
			||||||
 | 
						JSON   interface{} `json:"json"`
 | 
				
			||||||
 | 
						Origin string      `json:"origin"`
 | 
				
			||||||
 | 
						URL    string      `json:"url"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BasicPostJSONResponse struct {
 | 
				
			||||||
 | 
						Args    struct{} `json:"args"`
 | 
				
			||||||
 | 
						Data    string   `json:"data"`
 | 
				
			||||||
 | 
						Files   struct{} `json:"files"`
 | 
				
			||||||
 | 
						Form    struct{} `json:"form"`
 | 
				
			||||||
 | 
						Headers struct {
 | 
				
			||||||
 | 
							AcceptEncoding string `json:"Accept-Encoding"`
 | 
				
			||||||
 | 
							ContentLength  string `json:"Content-Length"`
 | 
				
			||||||
 | 
							ContentType    string `json:"Content-Type"`
 | 
				
			||||||
 | 
							Host           string `json:"Host"`
 | 
				
			||||||
 | 
							UserAgent      string `json:"User-Agent"`
 | 
				
			||||||
 | 
							XRequestedWith string `json:"X-Requested-With"`
 | 
				
			||||||
 | 
						} `json:"headers"`
 | 
				
			||||||
 | 
						JSON struct {
 | 
				
			||||||
 | 
							One string `json:"One"`
 | 
				
			||||||
 | 
						} `json:"json"`
 | 
				
			||||||
 | 
						Origin string `json:"origin"`
 | 
				
			||||||
 | 
						URL    string `json:"url"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BasicMultiFileUploadResponse struct {
 | 
				
			||||||
 | 
						Args  struct{} `json:"args"`
 | 
				
			||||||
 | 
						Data  string   `json:"data"`
 | 
				
			||||||
 | 
						Files struct {
 | 
				
			||||||
 | 
							File1 string `json:"file1"`
 | 
				
			||||||
 | 
							File2 string `json:"file2"`
 | 
				
			||||||
 | 
						} `json:"files"`
 | 
				
			||||||
 | 
						Form struct {
 | 
				
			||||||
 | 
							One string `json:"One"`
 | 
				
			||||||
 | 
						} `json:"form"`
 | 
				
			||||||
 | 
						Headers struct {
 | 
				
			||||||
 | 
							AcceptEncoding string `json:"Accept-Encoding"`
 | 
				
			||||||
 | 
							ContentLength  string `json:"Content-Length"`
 | 
				
			||||||
 | 
							ContentType    string `json:"Content-Type"`
 | 
				
			||||||
 | 
							Host           string `json:"Host"`
 | 
				
			||||||
 | 
							UserAgent      string `json:"User-Agent"`
 | 
				
			||||||
 | 
						} `json:"headers"`
 | 
				
			||||||
 | 
						JSON   interface{} `json:"json"`
 | 
				
			||||||
 | 
						Origin string      `json:"origin"`
 | 
				
			||||||
 | 
						URL    string      `json:"url"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type BasicPostFileUpload struct {
 | 
				
			||||||
 | 
						Args  struct{} `json:"args"`
 | 
				
			||||||
 | 
						Data  string   `json:"data"`
 | 
				
			||||||
 | 
						Files struct {
 | 
				
			||||||
 | 
							File string `json:"file"`
 | 
				
			||||||
 | 
						} `json:"files"`
 | 
				
			||||||
 | 
						Form struct {
 | 
				
			||||||
 | 
							One string `json:"one"`
 | 
				
			||||||
 | 
						} `json:"form"`
 | 
				
			||||||
 | 
						Headers struct {
 | 
				
			||||||
 | 
							AcceptEncoding string `json:"Accept-Encoding"`
 | 
				
			||||||
 | 
							ContentLength  string `json:"Content-Length"`
 | 
				
			||||||
 | 
							ContentType    string `json:"Content-Type"`
 | 
				
			||||||
 | 
							Host           string `json:"Host"`
 | 
				
			||||||
 | 
							UserAgent      string `json:"User-Agent"`
 | 
				
			||||||
 | 
						} `json:"headers"`
 | 
				
			||||||
 | 
						JSON   interface{} `json:"json"`
 | 
				
			||||||
 | 
						Origin string      `json:"origin"`
 | 
				
			||||||
 | 
						URL    string      `json:"url"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type XMLPostMessage struct {
 | 
				
			||||||
 | 
						Name   string
 | 
				
			||||||
 | 
						Age    int
 | 
				
			||||||
 | 
						Height int
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type dataAndErrorBuffer struct {
 | 
				
			||||||
 | 
						err error
 | 
				
			||||||
 | 
						bytes.Buffer
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (dataAndErrorBuffer) Close() error { return nil }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r dataAndErrorBuffer) Read(p []byte) (n int, err error) {
 | 
				
			||||||
 | 
						return 0, r.err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{Data: map[string]string{"One": "Two"}})
 | 
				
			||||||
 | 
						verifyOkPostResponse(resp, t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicRegularPostRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{Data: map[string]string{"One": "Two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Cannot post: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						verifyOkPostResponse(resp, t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{Data: map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
								Params: map[string]string{"1": "2"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestInvalidURLNoParams(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("%../dir/", &RequestOptions{Data: map[string]string{"One": "Two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPostRequestInvalidURLNoParams(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Post("%../dir/", &RequestOptions{Data: map[string]string{"One": "Two"}}); err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLPostRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLSessionPostRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := session.Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostJsonRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						_, err := Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: map[string]string{"One": "Two"}, IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPostJsonRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err := session.Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: map[string]string{"One": "Two"}, IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostJsonRequestInvalidJSON(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: math.NaN(), IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok == true {
 | 
				
			||||||
 | 
							t.Error("Somehow the request is OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPostJsonRequestInvalidJSON(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: math.NaN(), IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok == true {
 | 
				
			||||||
 | 
							t.Error("Somehow the request is OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostJsonRequestInvalidXML(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{XML: map[string]string{"One": "two"}, IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok == true {
 | 
				
			||||||
 | 
							t.Error("Somehow the request is OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPostJsonRequestInvalidXML(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{XML: map[string]string{"One": "two"}, IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the request went through")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok == true {
 | 
				
			||||||
 | 
							t.Error("Somehow the request is OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUploadInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer fd[0].FileContents.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error == nil {
 | 
				
			||||||
 | 
							t.Fatal("Somehow able to make the request")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPostRequestUploadInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						defer fd[0].FileContents.Close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = session.Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Fatal("Somehow able to make the request")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUploadInvalidFileUpload(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: []FileUpload{{FileName: `\x00%'"üfdsufhid\Ä\"D\\\"JS%25//'"H•\\\\'"¶•ªç∂\uf8\x8AKÔÓÔ`, FileContents: nil}},
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error == nil {
 | 
				
			||||||
 | 
							t.Fatal("Somehow able to make the request")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPostRequestUploadInvalidFileUpload(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
						_, err := session.Post("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: []FileUpload{{FileName: "üfdsufhidÄDJSHAKÔÓÔ", FileContents: nil}},
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Fatal("Somehow able to make the request")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLPostRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myXMLStruct := &XMLPostMessage{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						xml.Unmarshal([]byte(myJSONStruct.Data), myXMLStruct)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myXMLStruct.Age != 1 {
 | 
				
			||||||
 | 
							t.Errorf("Unable to serialize XML response from within JSON %#v ", myXMLStruct)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLPostRequestReaderBody(t *testing.T) {
 | 
				
			||||||
 | 
						msg := XMLPostMessage{Name: "Human", Age: 1, Height: 1}
 | 
				
			||||||
 | 
						derBytes, err := xml.Marshal(msg)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to marshal XML", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{RequestBody: bytes.NewReader(derBytes)})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myXMLStruct := &XMLPostMessage{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						xml.Unmarshal([]byte(myJSONStruct.Data), myXMLStruct)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myXMLStruct.Age != 1 {
 | 
				
			||||||
 | 
							t.Errorf("Unable to serialize XML response from within JSON %#v ", myXMLStruct)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLMarshaledStringPostRequest(t *testing.T) {
 | 
				
			||||||
 | 
						xmlStruct := XMLPostMessage{Name: "Human", Age: 1, Height: 1}
 | 
				
			||||||
 | 
						encoded, _ := xml.Marshal(xmlStruct)
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{XML: string(encoded)})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to response to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Data != string(encoded) {
 | 
				
			||||||
 | 
							t.Error("Response is not valid", myJSONStruct.Data, string(encoded))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLMarshaledBytesPostRequest(t *testing.T) {
 | 
				
			||||||
 | 
						xmlStruct := XMLPostMessage{Name: "Human", Age: 1, Height: 1}
 | 
				
			||||||
 | 
						encoded, _ := xml.Marshal(xmlStruct)
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{XML: encoded})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to response to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Data != string(encoded) {
 | 
				
			||||||
 | 
							t.Error("Response is not valid", myJSONStruct.Data, string(encoded))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestXMLNilPostRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post", &RequestOptions{XML: nil})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to response to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Data != "" {
 | 
				
			||||||
 | 
							t.Error("Response is not valid", myJSONStruct.Data)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUploadErrorReader(t *testing.T) {
 | 
				
			||||||
 | 
						var rd dataAndErrorBuffer
 | 
				
			||||||
 | 
						rd.err = fmt.Errorf("Random Error")
 | 
				
			||||||
 | 
						_, err := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: []FileUpload{{FileName: "Random.test", FileContents: rd}},
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow our test didn't fail...")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUploadErrorEOFReader(t *testing.T) {
 | 
				
			||||||
 | 
						var rd dataAndErrorBuffer
 | 
				
			||||||
 | 
						rd.err = io.EOF
 | 
				
			||||||
 | 
						_, err := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: []FileUpload{{FileName: "Random.test", FileContents: rd}},
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Somehow our test didn't fail... ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUpload(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostFileUpload{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Files.File != "saucy sauce" {
 | 
				
			||||||
 | 
							t.Error("File upload contents have been modified: ", myJSONStruct.Files.File)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Form.One != "Two" {
 | 
				
			||||||
 | 
							t.Error("Unable to parse form properly", myJSONStruct.Form)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUploadWithMime(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := os.Open("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: []FileUpload{{FileContents: fd, FileMime: "text/plain"}},
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostFileUpload{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Files.File != "saucy sauce" {
 | 
				
			||||||
 | 
							t.Error("File upload contents have been modified: ", myJSONStruct.Files.File)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Form.One != "Two" {
 | 
				
			||||||
 | 
							t.Error("Unable to parse form properly", myJSONStruct.Form)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO: Ensure file field contains correct content-type, field, and
 | 
				
			||||||
 | 
						// filename information as soon as
 | 
				
			||||||
 | 
						// https://github.com/kennethreitz/httpbin/pull/388 gets merged
 | 
				
			||||||
 | 
						// (Or figure out a way to test this case the PR is rejected)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostRequestUploadMultipleFiles(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := FileUploadFromGlob("testdata/*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to glob file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicMultiFileUploadResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Files.File2 != "saucy sauce" {
 | 
				
			||||||
 | 
							t.Error("File upload contents have been modified: ", myJSONStruct.Files.File2)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if myJSONStruct.Files.File1 != "I am just here to test the glob" {
 | 
				
			||||||
 | 
							t.Error("File upload contents have been modified: ", myJSONStruct.Files.File1)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Form.One != "Two" {
 | 
				
			||||||
 | 
							t.Error("Unable to parse form properly", myJSONStruct.Form)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostJsonBytesRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: []byte(`{"One":"Two"}`), IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.JSON.One != "Two" {
 | 
				
			||||||
 | 
							t.Error("Invalid post response: ", myJSONStruct.JSON.One)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.TrimSpace(myJSONStruct.Data) != `{"One":"Two"}` {
 | 
				
			||||||
 | 
							t.Error("JSON not properly returned: ", myJSONStruct.Data)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.XRequestedWith != "XMLHttpRequest" {
 | 
				
			||||||
 | 
							t.Error("Invalid requested header: ", myJSONStruct.Headers.XRequestedWith)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostJsonStringRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: `{"One":"Two"}`, IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.JSON.One != "Two" {
 | 
				
			||||||
 | 
							t.Error("Invalid post response: ", myJSONStruct.JSON.One)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.TrimSpace(myJSONStruct.Data) != `{"One":"Two"}` {
 | 
				
			||||||
 | 
							t.Error("JSON not properly returned: ", myJSONStruct.Data)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.XRequestedWith != "XMLHttpRequest" {
 | 
				
			||||||
 | 
							t.Error("Invalid requested header: ", myJSONStruct.Headers.XRequestedWith)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPostJsonRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, _ := Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&RequestOptions{JSON: map[string]string{"One": "Two"}, IsAjax: true})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostJSONResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.JSON.One != "Two" {
 | 
				
			||||||
 | 
							t.Error("Invalid post response: ", myJSONStruct.JSON.One)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if strings.TrimSpace(myJSONStruct.Data) != `{"One":"Two"}` {
 | 
				
			||||||
 | 
							t.Error("JSON not properly returned: ", myJSONStruct.Data)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.XRequestedWith != "XMLHttpRequest" {
 | 
				
			||||||
 | 
							t.Error("Invalid requested header: ", myJSONStruct.Headers.XRequestedWith)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPostSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Post("http://httpbin.org/post", &RequestOptions{Data: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cookieURL, err := url.Parse("http://httpbin.org")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("We (for some reason) cannot parse the cookie URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
 | 
				
			||||||
 | 
							t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
 | 
				
			||||||
 | 
							switch cookie.Name {
 | 
				
			||||||
 | 
							case "one":
 | 
				
			||||||
 | 
								if cookie.Value != "two" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "two":
 | 
				
			||||||
 | 
								if cookie.Value != "three" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "three":
 | 
				
			||||||
 | 
								if cookie.Value != "four" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								t.Error("We should not have any other cookies: ", cookie)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// verifyResponse will verify the following conditions
 | 
				
			||||||
 | 
					// 1. The request didn't return an error
 | 
				
			||||||
 | 
					// 2. The response returned an OK (a status code within the 200 range)
 | 
				
			||||||
 | 
					// 3. The output can be coerced to JSON (this may change later)
 | 
				
			||||||
 | 
					// It should only be run when testing GET request to http://httpbin.org/post expecting JSON
 | 
				
			||||||
 | 
					func verifyOkPostResponse(resp *Response, t *testing.T) *BasicPostResponse {
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Fatal("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						myJSONStruct := &BasicPostResponse{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.JSON(myJSONStruct); err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to coerce to JSON", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.URL != "http://httpbin.org/post" {
 | 
				
			||||||
 | 
							t.Error("For some reason the URL isn't the same", myJSONStruct.URL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Headers.Host != "httpbin.org" {
 | 
				
			||||||
 | 
							t.Error("The host header is invalid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if myJSONStruct.Form.One != "Two" {
 | 
				
			||||||
 | 
							t.Errorf("Invalid post response: %#v", myJSONStruct.Form)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Bytes() != nil {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (Bytes)", resp.Bytes())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.String() != "" {
 | 
				
			||||||
 | 
							t.Error("JSON decoding did not fully consume the response stream (String)", resp.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.StatusCode != 200 {
 | 
				
			||||||
 | 
							t.Error("Response returned a non-200 code")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return myJSONStruct
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPostInvalidURLSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Post("%../dir/", nil); err == nil {
 | 
				
			||||||
 | 
							t.Error("Some how the request was valid to make request ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										163
									
								
								vendor/github.com/levigross/grequests/base_put_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										163
									
								
								vendor/github.com/levigross/grequests/base_put_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,163 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPutRequest(t *testing.T) {
 | 
				
			||||||
 | 
						resp, err := Put("http://httpbin.org/put", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPutUploadRequest(t *testing.T) {
 | 
				
			||||||
 | 
						t.Skip("httpbin.org is broken, as of https://github.com/kennethreitz/httpbin/issues/340#issuecomment-330176449")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, _ := Put("http://httpbin.org/put",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Error != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestBasicPutUploadRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = Put("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Fatal("Somehow able to make the request")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSessionPutUploadRequestInvalidURL(t *testing.T) {
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("testdata/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = session.Put("%../dir/",
 | 
				
			||||||
 | 
							&RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Fatal("Somehow able to make the request")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPutSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"two": "three"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Get("http://httpbin.org/cookies/set", &RequestOptions{Params: map[string]string{"three": "four"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err = session.Put("http://httpbin.org/put", &RequestOptions{Data: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Error("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cookieURL, err := url.Parse("http://httpbin.org")
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("We (for some reason) cannot parse the cookie URL")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(session.HTTPClient.Jar.Cookies(cookieURL)) != 3 {
 | 
				
			||||||
 | 
							t.Error("Invalid number of cookies provided: ", session.HTTPClient.Jar.Cookies(cookieURL))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, cookie := range session.HTTPClient.Jar.Cookies(cookieURL) {
 | 
				
			||||||
 | 
							switch cookie.Name {
 | 
				
			||||||
 | 
							case "one":
 | 
				
			||||||
 | 
								if cookie.Value != "two" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "two":
 | 
				
			||||||
 | 
								if cookie.Value != "three" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							case "three":
 | 
				
			||||||
 | 
								if cookie.Value != "four" {
 | 
				
			||||||
 | 
									t.Error("Cookie value is not valid", cookie)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							default:
 | 
				
			||||||
 | 
								t.Error("We should not have any other cookies: ", cookie)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPutInvalidURLSession(t *testing.T) {
 | 
				
			||||||
 | 
						session := NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := session.Put("%../dir/", nil); err == nil {
 | 
				
			||||||
 | 
							t.Error("Some how the request was valid to make request ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										323
									
								
								vendor/github.com/levigross/grequests/example_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										323
									
								
								vendor/github.com/levigross/grequests/example_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,323 @@
 | 
				
			|||||||
 | 
					package grequests_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/xml"
 | 
				
			||||||
 | 
						"io"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/levigross/grequests"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_basicGet() {
 | 
				
			||||||
 | 
						// This is a very basic GET request
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println(resp.String())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_basicGetCustomHTTPClient() {
 | 
				
			||||||
 | 
						// This is a very basic GET request
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", &grequests.RequestOptions{HTTPClient: http.DefaultClient})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println(resp.String())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_proxy() {
 | 
				
			||||||
 | 
						proxyURL, err := url.Parse("http://127.0.0.1:8080") // Proxy URL
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Panicln(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://www.levigross.com/",
 | 
				
			||||||
 | 
							&grequests.RequestOptions{Proxies: map[string]*url.URL{proxyURL.Scheme: proxyURL}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println(resp)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_cookies() {
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/cookies",
 | 
				
			||||||
 | 
							&grequests.RequestOptions{
 | 
				
			||||||
 | 
								Cookies: []*http.Cookie{
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										Name:     "TestCookie",
 | 
				
			||||||
 | 
										Value:    "Random Value",
 | 
				
			||||||
 | 
										HttpOnly: true,
 | 
				
			||||||
 | 
										Secure:   false,
 | 
				
			||||||
 | 
									}, {
 | 
				
			||||||
 | 
										Name:     "AnotherCookie",
 | 
				
			||||||
 | 
										Value:    "Some Value",
 | 
				
			||||||
 | 
										HttpOnly: true,
 | 
				
			||||||
 | 
										Secure:   false,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println(resp.String())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_session() {
 | 
				
			||||||
 | 
						session := grequests.NewSession(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := session.Get("http://httpbin.org/cookies/set", &grequests.RequestOptions{Params: map[string]string{"one": "two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatal("Cannot set cookie: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println(resp.String())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_parse_XML() {
 | 
				
			||||||
 | 
						type GetXMLSample struct {
 | 
				
			||||||
 | 
							XMLName xml.Name `xml:"slideshow"`
 | 
				
			||||||
 | 
							Title   string   `xml:"title,attr"`
 | 
				
			||||||
 | 
							Date    string   `xml:"date,attr"`
 | 
				
			||||||
 | 
							Author  string   `xml:"author,attr"`
 | 
				
			||||||
 | 
							Slide   []struct {
 | 
				
			||||||
 | 
								Type  string `xml:"type,attr"`
 | 
				
			||||||
 | 
								Title string `xml:"title"`
 | 
				
			||||||
 | 
							} `xml:"slide"`
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/xml", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						userXML := &GetXMLSample{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// func xmlASCIIDecoder(charset string, input io.Reader) (io.Reader, error) {
 | 
				
			||||||
 | 
						// 	return input, nil
 | 
				
			||||||
 | 
						// }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If the server returns XML encoded in another charset (not UTF-8) – you
 | 
				
			||||||
 | 
						// must provide an encoder function that looks like the one I wrote above.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If you an consuming UTF-8 just pass `nil` into the second arg
 | 
				
			||||||
 | 
						if err := resp.XML(userXML, xmlASCIIDecoder); err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to consume the response as XML: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if userXML.Title != "Sample Slide Show" {
 | 
				
			||||||
 | 
							log.Printf("Invalid XML serialization %#v", userXML)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_customUserAgent() {
 | 
				
			||||||
 | 
						ro := &grequests.RequestOptions{UserAgent: "LeviBot 0.1"}
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", ro)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatal("Oops something went wrong: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						log.Println(resp.String())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_basicAuth() {
 | 
				
			||||||
 | 
						ro := &grequests.RequestOptions{Auth: []string{"Levi", "Bot"}}
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", ro)
 | 
				
			||||||
 | 
						// Not the usual JSON so copy and paste from below
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_customHTTPHeader() {
 | 
				
			||||||
 | 
						ro := &grequests.RequestOptions{UserAgent: "LeviBot 0.1",
 | 
				
			||||||
 | 
							Headers: map[string]string{"X-Wonderful-Header": "1"}}
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", ro)
 | 
				
			||||||
 | 
						// Not the usual JSON so copy and paste from below
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_acceptInvalidTLSCert() {
 | 
				
			||||||
 | 
						ro := &grequests.RequestOptions{InsecureSkipVerify: true}
 | 
				
			||||||
 | 
						resp, err := grequests.Get("https://www.pcwebshop.co.uk/", ro)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_urlQueryParams() {
 | 
				
			||||||
 | 
						ro := &grequests.RequestOptions{
 | 
				
			||||||
 | 
							Params: map[string]string{"Hello": "World", "Goodbye": "World"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", ro)
 | 
				
			||||||
 | 
						// url will now be http://httpbin.org/get?hello=world&goodbye=world
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_downloadFile() {
 | 
				
			||||||
 | 
						resp, err := grequests.Get("http://httpbin.org/get", nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := resp.DownloadToFile("randomFile"); err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to download to file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to download file", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_postForm() {
 | 
				
			||||||
 | 
						resp, err := grequests.Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&grequests.RequestOptions{Data: map[string]string{"One": "Two"}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// This is the basic form POST. The request body will be `one=two`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Cannot post: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_postXML() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						type XMLPostMessage struct {
 | 
				
			||||||
 | 
							Name   string
 | 
				
			||||||
 | 
							Age    int
 | 
				
			||||||
 | 
							Height int
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						resp, err := grequests.Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&grequests.RequestOptions{XML: XMLPostMessage{Name: "Human", Age: 1, Height: 1}})
 | 
				
			||||||
 | 
						// The request body will contain the XML generated by the `XMLPostMessage` struct
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_postFileUpload() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd, err := grequests.FileUploadFromDisk("test_files/mypassword")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to open file: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// This will upload the file as a multipart mime request
 | 
				
			||||||
 | 
						resp, err := grequests.Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&grequests.RequestOptions{
 | 
				
			||||||
 | 
								Files: fd,
 | 
				
			||||||
 | 
								Data:  map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Example_postJSONAJAX() {
 | 
				
			||||||
 | 
						resp, err := grequests.Post("http://httpbin.org/post",
 | 
				
			||||||
 | 
							&grequests.RequestOptions{
 | 
				
			||||||
 | 
								JSON:   map[string]string{"One": "Two"},
 | 
				
			||||||
 | 
								IsAjax: true, // this adds the X-Requested-With: XMLHttpRequest header
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Println("Unable to make request", resp.Error)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							log.Println("Request did not return OK")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func xmlASCIIDecoder(charset string, input io.Reader) (io.Reader, error) {
 | 
				
			||||||
 | 
						return input, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										53
									
								
								vendor/github.com/levigross/grequests/file_upload_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								vendor/github.com/levigross/grequests/file_upload_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestErrorOpenFile(t *testing.T) {
 | 
				
			||||||
 | 
						fd, err := FileUploadFromDisk("I am Not A File")
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							t.Error("We are not getting an error back from our non existent file: ")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if fd != nil {
 | 
				
			||||||
 | 
							t.Error("We actually got back a pointer: ", fd)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGLOBFiles(t *testing.T) {
 | 
				
			||||||
 | 
						fd, err := FileUploadFromGlob("testdata/*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Got an invalid GLOB: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(fd) != 2 {
 | 
				
			||||||
 | 
							t.Error("Some how we have more than two files in our glob", len(fd), fd)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInvalidGlob(t *testing.T) {
 | 
				
			||||||
 | 
						if _, err := FileUploadFromGlob("[-]"); err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow the glob worked")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNoGlobFiles(t *testing.T) {
 | 
				
			||||||
 | 
						if _, err := FileUploadFromGlob("notapath"); err == nil {
 | 
				
			||||||
 | 
							t.Error("Somehow got a valid GLOB")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGlobWithDir(t *testing.T) {
 | 
				
			||||||
 | 
						fd, err := FileUploadFromGlob("*test*")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Glob failed", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, f := range fd {
 | 
				
			||||||
 | 
							if f.FileName == "test_files" {
 | 
				
			||||||
 | 
								t.Error(f, "is a dir (which cannot be uploaded)")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										39
									
								
								vendor/github.com/levigross/grequests/request_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								vendor/github.com/levigross/grequests/request_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAddQueryStringParams(t *testing.T) {
 | 
				
			||||||
 | 
						userURL, err := buildURLParams("https://www.google.com/", map[string]string{"1": "2", "3": "4"})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("URL Parse Error: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if userURL != "https://www.google.com/?1=2&3=4" {
 | 
				
			||||||
 | 
							t.Error("URL params not properly built", userURL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSortAddQueryStringParams(t *testing.T) {
 | 
				
			||||||
 | 
						userURL, err := buildURLParams("https://www.google.com/", map[string]string{"3": "4", "1": "2"})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("URL Parse Error: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if userURL != "https://www.google.com/?1=2&3=4" {
 | 
				
			||||||
 | 
							t.Error("URL params not properly built and sorted", userURL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestAddQueryStringParamsExistingParam(t *testing.T) {
 | 
				
			||||||
 | 
						userURL, err := buildURLParams("https://www.google.com/?5=6", map[string]string{"3": "4", "1": "2"})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("URL Parse Error: ", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if userURL != "https://www.google.com/?1=2&3=4&5=6" {
 | 
				
			||||||
 | 
							t.Error("URL params not properly built and sorted", userURL)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										26
									
								
								vendor/github.com/levigross/grequests/response_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								vendor/github.com/levigross/grequests/response_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestResponseOk(t *testing.T) {
 | 
				
			||||||
 | 
						status := []int{200, 201, 202, 203, 204, 205, 206, 207, 208, 226}
 | 
				
			||||||
 | 
						for _, status := range status {
 | 
				
			||||||
 | 
							verifyResponseOkForStatus(status, t)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func verifyResponseOkForStatus(status int, t *testing.T) {
 | 
				
			||||||
 | 
						url := "http://httpbin.org/status/" + strconv.Itoa(status)
 | 
				
			||||||
 | 
						resp, err := Get(url, nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Error("Unable to make request", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if resp.Ok != true {
 | 
				
			||||||
 | 
							t.Errorf("Request did not return OK. Received status code %d rather a 2xx.", resp.StatusCode)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1
									
								
								vendor/github.com/levigross/grequests/testdata/herefortheglob
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/levigross/grequests/testdata/herefortheglob
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					I am just here to test the glob
 | 
				
			||||||
							
								
								
									
										1
									
								
								vendor/github.com/levigross/grequests/testdata/mypassword
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/levigross/grequests/testdata/mypassword
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					saucy sauce
 | 
				
			||||||
							
								
								
									
										1
									
								
								vendor/github.com/levigross/grequests/utils_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								vendor/github.com/levigross/grequests/utils_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					package grequests
 | 
				
			||||||
							
								
								
									
										1778
									
								
								vendor/github.com/stretchr/testify/assert/assertions_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1778
									
								
								vendor/github.com/stretchr/testify/assert/assertions_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										611
									
								
								vendor/github.com/stretchr/testify/assert/forward_assertions_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										611
									
								
								vendor/github.com/stretchr/testify/assert/forward_assertions_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,611 @@
 | 
				
			|||||||
 | 
					package assert
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"regexp"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestImplementsWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Implements((*AssertionTesterInterface)(nil), new(AssertionTesterConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("Implements method should return true: AssertionTesterConformingObject implements AssertionTesterInterface")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.Implements((*AssertionTesterInterface)(nil), new(AssertionTesterNonConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("Implements method should return false: AssertionTesterNonConformingObject does not implements AssertionTesterInterface")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestIsTypeWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.IsType(new(AssertionTesterConformingObject), new(AssertionTesterConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("IsType should return true: AssertionTesterConformingObject is the same type as AssertionTesterConformingObject")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.IsType(new(AssertionTesterConformingObject), new(AssertionTesterNonConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("IsType should return false: AssertionTesterConformingObject is not the same type as AssertionTesterNonConformingObject")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestEqualWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Equal("Hello World", "Hello World") {
 | 
				
			||||||
 | 
							t.Error("Equal should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.Equal(123, 123) {
 | 
				
			||||||
 | 
							t.Error("Equal should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.Equal(123.5, 123.5) {
 | 
				
			||||||
 | 
							t.Error("Equal should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.Equal([]byte("Hello World"), []byte("Hello World")) {
 | 
				
			||||||
 | 
							t.Error("Equal should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.Equal(nil, nil) {
 | 
				
			||||||
 | 
							t.Error("Equal should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestEqualValuesWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.EqualValues(uint32(10), int32(10)) {
 | 
				
			||||||
 | 
							t.Error("EqualValues should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNotNilWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.NotNil(new(AssertionTesterConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("NotNil should return true: object is not nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.NotNil(nil) {
 | 
				
			||||||
 | 
							t.Error("NotNil should return false: object is nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNilWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Nil(nil) {
 | 
				
			||||||
 | 
							t.Error("Nil should return true: object is nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.Nil(new(AssertionTesterConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("Nil should return false: object is not nil")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTrueWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.True(true) {
 | 
				
			||||||
 | 
							t.Error("True should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.True(false) {
 | 
				
			||||||
 | 
							t.Error("True should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestFalseWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.False(false) {
 | 
				
			||||||
 | 
							t.Error("False should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.False(true) {
 | 
				
			||||||
 | 
							t.Error("False should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestExactlyWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						a := float32(1)
 | 
				
			||||||
 | 
						b := float64(1)
 | 
				
			||||||
 | 
						c := float32(1)
 | 
				
			||||||
 | 
						d := float32(2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if assert.Exactly(a, b) {
 | 
				
			||||||
 | 
							t.Error("Exactly should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.Exactly(a, d) {
 | 
				
			||||||
 | 
							t.Error("Exactly should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.Exactly(a, c) {
 | 
				
			||||||
 | 
							t.Error("Exactly should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if assert.Exactly(nil, a) {
 | 
				
			||||||
 | 
							t.Error("Exactly should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.Exactly(a, nil) {
 | 
				
			||||||
 | 
							t.Error("Exactly should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNotEqualWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.NotEqual("Hello World", "Hello World!") {
 | 
				
			||||||
 | 
							t.Error("NotEqual should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.NotEqual(123, 1234) {
 | 
				
			||||||
 | 
							t.Error("NotEqual should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.NotEqual(123.5, 123.55) {
 | 
				
			||||||
 | 
							t.Error("NotEqual should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.NotEqual([]byte("Hello World"), []byte("Hello World!")) {
 | 
				
			||||||
 | 
							t.Error("NotEqual should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !assert.NotEqual(nil, new(AssertionTesterConformingObject)) {
 | 
				
			||||||
 | 
							t.Error("NotEqual should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestContainsWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						list := []string{"Foo", "Bar"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Contains("Hello World", "Hello") {
 | 
				
			||||||
 | 
							t.Error("Contains should return true: \"Hello World\" contains \"Hello\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.Contains("Hello World", "Salut") {
 | 
				
			||||||
 | 
							t.Error("Contains should return false: \"Hello World\" does not contain \"Salut\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Contains(list, "Foo") {
 | 
				
			||||||
 | 
							t.Error("Contains should return true: \"[\"Foo\", \"Bar\"]\" contains \"Foo\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.Contains(list, "Salut") {
 | 
				
			||||||
 | 
							t.Error("Contains should return false: \"[\"Foo\", \"Bar\"]\" does not contain \"Salut\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNotContainsWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						list := []string{"Foo", "Bar"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.NotContains("Hello World", "Hello!") {
 | 
				
			||||||
 | 
							t.Error("NotContains should return true: \"Hello World\" does not contain \"Hello!\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.NotContains("Hello World", "Hello") {
 | 
				
			||||||
 | 
							t.Error("NotContains should return false: \"Hello World\" contains \"Hello\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.NotContains(list, "Foo!") {
 | 
				
			||||||
 | 
							t.Error("NotContains should return true: \"[\"Foo\", \"Bar\"]\" does not contain \"Foo!\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if assert.NotContains(list, "Foo") {
 | 
				
			||||||
 | 
							t.Error("NotContains should return false: \"[\"Foo\", \"Bar\"]\" contains \"Foo\"")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestConditionWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Condition(func() bool { return true }, "Truth") {
 | 
				
			||||||
 | 
							t.Error("Condition should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if assert.Condition(func() bool { return false }, "Lie") {
 | 
				
			||||||
 | 
							t.Error("Condition should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestDidPanicWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if funcDidPanic, _ := didPanic(func() {
 | 
				
			||||||
 | 
							panic("Panic!")
 | 
				
			||||||
 | 
						}); !funcDidPanic {
 | 
				
			||||||
 | 
							t.Error("didPanic should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if funcDidPanic, _ := didPanic(func() {
 | 
				
			||||||
 | 
						}); funcDidPanic {
 | 
				
			||||||
 | 
							t.Error("didPanic should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPanicsWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.Panics(func() {
 | 
				
			||||||
 | 
							panic("Panic!")
 | 
				
			||||||
 | 
						}) {
 | 
				
			||||||
 | 
							t.Error("Panics should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if assert.Panics(func() {
 | 
				
			||||||
 | 
						}) {
 | 
				
			||||||
 | 
							t.Error("Panics should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNotPanicsWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if !assert.NotPanics(func() {
 | 
				
			||||||
 | 
						}) {
 | 
				
			||||||
 | 
							t.Error("NotPanics should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if assert.NotPanics(func() {
 | 
				
			||||||
 | 
							panic("Panic!")
 | 
				
			||||||
 | 
						}) {
 | 
				
			||||||
 | 
							t.Error("NotPanics should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNoErrorWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// start with a nil error
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(mockAssert.NoError(err), "NoError should return True for nil arg")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// now set an error
 | 
				
			||||||
 | 
						err = errors.New("Some error")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.NoError(err), "NoError with error should return False")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestErrorWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// start with a nil error
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.Error(err), "Error should return False for nil arg")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// now set an error
 | 
				
			||||||
 | 
						err = errors.New("Some error")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(mockAssert.Error(err), "Error with error should return True")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestEqualErrorWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// start with a nil error
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						assert.False(mockAssert.EqualError(err, ""),
 | 
				
			||||||
 | 
							"EqualError should return false for nil arg")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// now set an error
 | 
				
			||||||
 | 
						err = errors.New("some error")
 | 
				
			||||||
 | 
						assert.False(mockAssert.EqualError(err, "Not some error"),
 | 
				
			||||||
 | 
							"EqualError should return false for different error string")
 | 
				
			||||||
 | 
						assert.True(mockAssert.EqualError(err, "some error"),
 | 
				
			||||||
 | 
							"EqualError should return true")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestEmptyWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(mockAssert.Empty(""), "Empty string is empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.Empty(nil), "Nil is empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.Empty([]string{}), "Empty string array is empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.Empty(0), "Zero int value is empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.Empty(false), "False value is empty")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.Empty("something"), "Non Empty string is not empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Empty(errors.New("something")), "Non nil object is not empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Empty([]string{"something"}), "Non empty string array is not empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Empty(1), "Non-zero int value is not empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Empty(true), "True value is not empty")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNotEmptyWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.NotEmpty(""), "Empty string is empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.NotEmpty(nil), "Nil is empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.NotEmpty([]string{}), "Empty string array is empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.NotEmpty(0), "Zero int value is empty")
 | 
				
			||||||
 | 
						assert.False(mockAssert.NotEmpty(false), "False value is empty")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(mockAssert.NotEmpty("something"), "Non Empty string is not empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.NotEmpty(errors.New("something")), "Non nil object is not empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.NotEmpty([]string{"something"}), "Non empty string array is not empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.NotEmpty(1), "Non-zero int value is not empty")
 | 
				
			||||||
 | 
						assert.True(mockAssert.NotEmpty(true), "True value is not empty")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestLenWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.Len(nil, 0), "nil does not have length")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Len(0, 0), "int does not have length")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Len(true, 0), "true does not have length")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Len(false, 0), "false does not have length")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Len('A', 0), "Rune does not have length")
 | 
				
			||||||
 | 
						assert.False(mockAssert.Len(struct{}{}, 0), "Struct does not have length")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ch := make(chan int, 5)
 | 
				
			||||||
 | 
						ch <- 1
 | 
				
			||||||
 | 
						ch <- 2
 | 
				
			||||||
 | 
						ch <- 3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cases := []struct {
 | 
				
			||||||
 | 
							v interface{}
 | 
				
			||||||
 | 
							l int
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{[]int{1, 2, 3}, 3},
 | 
				
			||||||
 | 
							{[...]int{1, 2, 3}, 3},
 | 
				
			||||||
 | 
							{"ABC", 3},
 | 
				
			||||||
 | 
							{map[int]int{1: 2, 2: 4, 3: 6}, 3},
 | 
				
			||||||
 | 
							{ch, 3},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							{[]int{}, 0},
 | 
				
			||||||
 | 
							{map[int]int{}, 0},
 | 
				
			||||||
 | 
							{make(chan int), 0},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							{[]int(nil), 0},
 | 
				
			||||||
 | 
							{map[int]int(nil), 0},
 | 
				
			||||||
 | 
							{(chan int)(nil), 0},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, c := range cases {
 | 
				
			||||||
 | 
							assert.True(mockAssert.Len(c.v, c.l), "%#v have %d items", c.v, c.l)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestWithinDurationWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
						a := time.Now()
 | 
				
			||||||
 | 
						b := a.Add(10 * time.Second)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(mockAssert.WithinDuration(a, b, 10*time.Second), "A 10s difference is within a 10s time difference")
 | 
				
			||||||
 | 
						assert.True(mockAssert.WithinDuration(b, a, 10*time.Second), "A 10s difference is within a 10s time difference")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.WithinDuration(a, b, 9*time.Second), "A 10s difference is not within a 9s time difference")
 | 
				
			||||||
 | 
						assert.False(mockAssert.WithinDuration(b, a, 9*time.Second), "A 10s difference is not within a 9s time difference")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.WithinDuration(a, b, -9*time.Second), "A 10s difference is not within a 9s time difference")
 | 
				
			||||||
 | 
						assert.False(mockAssert.WithinDuration(b, a, -9*time.Second), "A 10s difference is not within a 9s time difference")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.WithinDuration(a, b, -11*time.Second), "A 10s difference is not within a 9s time difference")
 | 
				
			||||||
 | 
						assert.False(mockAssert.WithinDuration(b, a, -11*time.Second), "A 10s difference is not within a 9s time difference")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInDeltaWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						True(t, assert.InDelta(1.001, 1, 0.01), "|1.001 - 1| <= 0.01")
 | 
				
			||||||
 | 
						True(t, assert.InDelta(1, 1.001, 0.01), "|1 - 1.001| <= 0.01")
 | 
				
			||||||
 | 
						True(t, assert.InDelta(1, 2, 1), "|1 - 2| <= 1")
 | 
				
			||||||
 | 
						False(t, assert.InDelta(1, 2, 0.5), "Expected |1 - 2| <= 0.5 to fail")
 | 
				
			||||||
 | 
						False(t, assert.InDelta(2, 1, 0.5), "Expected |2 - 1| <= 0.5 to fail")
 | 
				
			||||||
 | 
						False(t, assert.InDelta("", nil, 1), "Expected non numerals to fail")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cases := []struct {
 | 
				
			||||||
 | 
							a, b  interface{}
 | 
				
			||||||
 | 
							delta float64
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{uint8(2), uint8(1), 1},
 | 
				
			||||||
 | 
							{uint16(2), uint16(1), 1},
 | 
				
			||||||
 | 
							{uint32(2), uint32(1), 1},
 | 
				
			||||||
 | 
							{uint64(2), uint64(1), 1},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							{int(2), int(1), 1},
 | 
				
			||||||
 | 
							{int8(2), int8(1), 1},
 | 
				
			||||||
 | 
							{int16(2), int16(1), 1},
 | 
				
			||||||
 | 
							{int32(2), int32(1), 1},
 | 
				
			||||||
 | 
							{int64(2), int64(1), 1},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							{float32(2), float32(1), 1},
 | 
				
			||||||
 | 
							{float64(2), float64(1), 1},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tc := range cases {
 | 
				
			||||||
 | 
							True(t, assert.InDelta(tc.a, tc.b, tc.delta), "Expected |%V - %V| <= %v", tc.a, tc.b, tc.delta)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInEpsilonWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cases := []struct {
 | 
				
			||||||
 | 
							a, b    interface{}
 | 
				
			||||||
 | 
							epsilon float64
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{uint8(2), uint16(2), .001},
 | 
				
			||||||
 | 
							{2.1, 2.2, 0.1},
 | 
				
			||||||
 | 
							{2.2, 2.1, 0.1},
 | 
				
			||||||
 | 
							{-2.1, -2.2, 0.1},
 | 
				
			||||||
 | 
							{-2.2, -2.1, 0.1},
 | 
				
			||||||
 | 
							{uint64(100), uint8(101), 0.01},
 | 
				
			||||||
 | 
							{0.1, -0.1, 2},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tc := range cases {
 | 
				
			||||||
 | 
							True(t, assert.InEpsilon(tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cases = []struct {
 | 
				
			||||||
 | 
							a, b    interface{}
 | 
				
			||||||
 | 
							epsilon float64
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{uint8(2), int16(-2), .001},
 | 
				
			||||||
 | 
							{uint64(100), uint8(102), 0.01},
 | 
				
			||||||
 | 
							{2.1, 2.2, 0.001},
 | 
				
			||||||
 | 
							{2.2, 2.1, 0.001},
 | 
				
			||||||
 | 
							{2.1, -2.2, 1},
 | 
				
			||||||
 | 
							{2.1, "bla-bla", 0},
 | 
				
			||||||
 | 
							{0.1, -0.1, 1.99},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tc := range cases {
 | 
				
			||||||
 | 
							False(t, assert.InEpsilon(tc.a, tc.b, tc.epsilon, "Expected %V and %V to have a relative difference of %v", tc.a, tc.b, tc.epsilon))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestRegexpWrapper(t *testing.T) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cases := []struct {
 | 
				
			||||||
 | 
							rx, str string
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{"^start", "start of the line"},
 | 
				
			||||||
 | 
							{"end$", "in the end"},
 | 
				
			||||||
 | 
							{"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12.34"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tc := range cases {
 | 
				
			||||||
 | 
							True(t, assert.Regexp(tc.rx, tc.str))
 | 
				
			||||||
 | 
							True(t, assert.Regexp(regexp.MustCompile(tc.rx), tc.str))
 | 
				
			||||||
 | 
							False(t, assert.NotRegexp(tc.rx, tc.str))
 | 
				
			||||||
 | 
							False(t, assert.NotRegexp(regexp.MustCompile(tc.rx), tc.str))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cases = []struct {
 | 
				
			||||||
 | 
							rx, str string
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{"^asdfastart", "Not the start of the line"},
 | 
				
			||||||
 | 
							{"end$", "in the end."},
 | 
				
			||||||
 | 
							{"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12a.34"},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tc := range cases {
 | 
				
			||||||
 | 
							False(t, assert.Regexp(tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str)
 | 
				
			||||||
 | 
							False(t, assert.Regexp(regexp.MustCompile(tc.rx), tc.str))
 | 
				
			||||||
 | 
							True(t, assert.NotRegexp(tc.rx, tc.str))
 | 
				
			||||||
 | 
							True(t, assert.NotRegexp(regexp.MustCompile(tc.rx), tc.str))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestZeroWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, test := range zeros {
 | 
				
			||||||
 | 
							assert.True(mockAssert.Zero(test), "Zero should return true for %v", test)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, test := range nonZeros {
 | 
				
			||||||
 | 
							assert.False(mockAssert.Zero(test), "Zero should return false for %v", test)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNotZeroWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, test := range zeros {
 | 
				
			||||||
 | 
							assert.False(mockAssert.NotZero(test), "Zero should return true for %v", test)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, test := range nonZeros {
 | 
				
			||||||
 | 
							assert.True(mockAssert.NotZero(test), "Zero should return false for %v", test)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_EqualSONString(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if !assert.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"hello": "world", "foo": "bar"}`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_EquivalentButNotEqual(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if !assert.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_HashOfArraysAndHashes(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if !assert.JSONEq("{\r\n\t\"numeric\": 1.5,\r\n\t\"array\": [{\"foo\": \"bar\"}, 1, \"string\", [\"nested\", \"array\", 5.5]],\r\n\t\"hash\": {\"nested\": \"hash\", \"nested_slice\": [\"this\", \"is\", \"nested\"]},\r\n\t\"string\": \"foo\"\r\n}",
 | 
				
			||||||
 | 
							"{\r\n\t\"numeric\": 1.5,\r\n\t\"hash\": {\"nested\": \"hash\", \"nested_slice\": [\"this\", \"is\", \"nested\"]},\r\n\t\"string\": \"foo\",\r\n\t\"array\": [{\"foo\": \"bar\"}, 1, \"string\", [\"nested\", \"array\", 5.5]]\r\n}") {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_Array(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if !assert.JSONEq(`["foo", {"hello": "world", "nested": "hash"}]`, `["foo", {"nested": "hash", "hello": "world"}]`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return true")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_HashAndArrayNotEquivalent(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if assert.JSONEq(`["foo", {"hello": "world", "nested": "hash"}]`, `{"foo": "bar", {"nested": "hash", "hello": "world"}}`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_HashesNotEquivalent(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if assert.JSONEq(`{"foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_ActualIsNotJSON(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if assert.JSONEq(`{"foo": "bar"}`, "Not JSON") {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_ExpectedIsNotJSON(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if assert.JSONEq("Not JSON", `{"foo": "bar", "hello": "world"}`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_ExpectedAndActualNotJSON(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if assert.JSONEq("Not JSON", "Not JSON") {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestJSONEqWrapper_ArraysOfDifferentOrder(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(new(testing.T))
 | 
				
			||||||
 | 
						if assert.JSONEq(`["foo", {"hello": "world", "nested": "hash"}]`, `[{ "hello": "world", "nested": "hash"}, "foo"]`) {
 | 
				
			||||||
 | 
							t.Error("JSONEq should return false")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										146
									
								
								vendor/github.com/stretchr/testify/assert/http_assertions_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										146
									
								
								vendor/github.com/stretchr/testify/assert/http_assertions_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,146 @@
 | 
				
			|||||||
 | 
					package assert
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func httpOK(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
						w.WriteHeader(http.StatusOK)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func httpRedirect(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
						w.WriteHeader(http.StatusTemporaryRedirect)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func httpError(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
						w.WriteHeader(http.StatusInternalServerError)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHTTPSuccess(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT1 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPSuccess(mockT1, httpOK, "GET", "/", nil), true)
 | 
				
			||||||
 | 
						assert.False(mockT1.Failed())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT2 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPSuccess(mockT2, httpRedirect, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.True(mockT2.Failed())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT3 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPSuccess(mockT3, httpError, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.True(mockT3.Failed())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHTTPRedirect(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT1 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPRedirect(mockT1, httpOK, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.True(mockT1.Failed())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT2 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPRedirect(mockT2, httpRedirect, "GET", "/", nil), true)
 | 
				
			||||||
 | 
						assert.False(mockT2.Failed())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT3 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPRedirect(mockT3, httpError, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.True(mockT3.Failed())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHTTPError(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT1 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPError(mockT1, httpOK, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.True(mockT1.Failed())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT2 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPError(mockT2, httpRedirect, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.True(mockT2.Failed())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mockT3 := new(testing.T)
 | 
				
			||||||
 | 
						assert.Equal(HTTPError(mockT3, httpError, "GET", "/", nil), true)
 | 
				
			||||||
 | 
						assert.False(mockT3.Failed())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHTTPStatusesWrapper(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPSuccess(httpOK, "GET", "/", nil), true)
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPSuccess(httpRedirect, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPSuccess(httpError, "GET", "/", nil), false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPRedirect(httpOK, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPRedirect(httpRedirect, "GET", "/", nil), true)
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPRedirect(httpError, "GET", "/", nil), false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPError(httpOK, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPError(httpRedirect, "GET", "/", nil), false)
 | 
				
			||||||
 | 
						assert.Equal(mockAssert.HTTPError(httpError, "GET", "/", nil), true)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func httpHelloName(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
						name := r.FormValue("name")
 | 
				
			||||||
 | 
						w.Write([]byte(fmt.Sprintf("Hello, %s!", name)))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHTTPRequestWithNoParams(t *testing.T) {
 | 
				
			||||||
 | 
						var got *http.Request
 | 
				
			||||||
 | 
						handler := func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
							got = r
 | 
				
			||||||
 | 
							w.WriteHeader(http.StatusOK)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						True(t, HTTPSuccess(t, handler, "GET", "/url", nil))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Empty(t, got.URL.Query())
 | 
				
			||||||
 | 
						Equal(t, "/url", got.URL.RequestURI())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHTTPRequestWithParams(t *testing.T) {
 | 
				
			||||||
 | 
						var got *http.Request
 | 
				
			||||||
 | 
						handler := func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
 | 
							got = r
 | 
				
			||||||
 | 
							w.WriteHeader(http.StatusOK)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						params := url.Values{}
 | 
				
			||||||
 | 
						params.Add("id", "12345")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						True(t, HTTPSuccess(t, handler, "GET", "/url", params))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Equal(t, url.Values{"id": []string{"12345"}}, got.URL.Query())
 | 
				
			||||||
 | 
						Equal(t, "/url?id=12345", got.URL.String())
 | 
				
			||||||
 | 
						Equal(t, "/url?id=12345", got.URL.RequestURI())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHttpBody(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockT := new(testing.T)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!"))
 | 
				
			||||||
 | 
						assert.True(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World"))
 | 
				
			||||||
 | 
						assert.False(HTTPBodyContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!"))
 | 
				
			||||||
 | 
						assert.False(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World"))
 | 
				
			||||||
 | 
						assert.True(HTTPBodyNotContains(mockT, httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world"))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestHttpBodyWrappers(t *testing.T) {
 | 
				
			||||||
 | 
						assert := New(t)
 | 
				
			||||||
 | 
						mockAssert := New(new(testing.T))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.True(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!"))
 | 
				
			||||||
 | 
						assert.True(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World"))
 | 
				
			||||||
 | 
						assert.False(mockAssert.HTTPBodyContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						assert.False(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "Hello, World!"))
 | 
				
			||||||
 | 
						assert.False(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "World"))
 | 
				
			||||||
 | 
						assert.True(mockAssert.HTTPBodyNotContains(httpHelloName, "GET", "/", url.Values{"name": []string{"World"}}, "world"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										416
									
								
								vendor/golang.org/x/net/publicsuffix/list_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										416
									
								
								vendor/golang.org/x/net/publicsuffix/list_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,416 @@
 | 
				
			|||||||
 | 
					// Copyright 2012 The Go Authors. All rights reserved.
 | 
				
			||||||
 | 
					// Use of this source code is governed by a BSD-style
 | 
				
			||||||
 | 
					// license that can be found in the LICENSE file.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package publicsuffix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"sort"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestNodeLabel(t *testing.T) {
 | 
				
			||||||
 | 
						for i, want := range nodeLabels {
 | 
				
			||||||
 | 
							got := nodeLabel(uint32(i))
 | 
				
			||||||
 | 
							if got != want {
 | 
				
			||||||
 | 
								t.Errorf("%d: got %q, want %q", i, got, want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestFind(t *testing.T) {
 | 
				
			||||||
 | 
						testCases := []string{
 | 
				
			||||||
 | 
							"",
 | 
				
			||||||
 | 
							"a",
 | 
				
			||||||
 | 
							"a0",
 | 
				
			||||||
 | 
							"aaaa",
 | 
				
			||||||
 | 
							"ao",
 | 
				
			||||||
 | 
							"ap",
 | 
				
			||||||
 | 
							"ar",
 | 
				
			||||||
 | 
							"aro",
 | 
				
			||||||
 | 
							"arp",
 | 
				
			||||||
 | 
							"arpa",
 | 
				
			||||||
 | 
							"arpaa",
 | 
				
			||||||
 | 
							"arpb",
 | 
				
			||||||
 | 
							"az",
 | 
				
			||||||
 | 
							"b",
 | 
				
			||||||
 | 
							"b0",
 | 
				
			||||||
 | 
							"ba",
 | 
				
			||||||
 | 
							"z",
 | 
				
			||||||
 | 
							"zu",
 | 
				
			||||||
 | 
							"zv",
 | 
				
			||||||
 | 
							"zw",
 | 
				
			||||||
 | 
							"zx",
 | 
				
			||||||
 | 
							"zy",
 | 
				
			||||||
 | 
							"zz",
 | 
				
			||||||
 | 
							"zzzz",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, tc := range testCases {
 | 
				
			||||||
 | 
							got := find(tc, 0, numTLD)
 | 
				
			||||||
 | 
							want := notFound
 | 
				
			||||||
 | 
							for i := uint32(0); i < numTLD; i++ {
 | 
				
			||||||
 | 
								if tc == nodeLabel(i) {
 | 
				
			||||||
 | 
									want = i
 | 
				
			||||||
 | 
									break
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if got != want {
 | 
				
			||||||
 | 
								t.Errorf("%q: got %d, want %d", tc, got, want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestICANN(t *testing.T) {
 | 
				
			||||||
 | 
						testCases := map[string]bool{
 | 
				
			||||||
 | 
							"foo.org":            true,
 | 
				
			||||||
 | 
							"foo.co.uk":          true,
 | 
				
			||||||
 | 
							"foo.dyndns.org":     false,
 | 
				
			||||||
 | 
							"foo.go.dyndns.org":  false,
 | 
				
			||||||
 | 
							"foo.blogspot.co.uk": false,
 | 
				
			||||||
 | 
							"foo.intranet":       false,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for domain, want := range testCases {
 | 
				
			||||||
 | 
							_, got := PublicSuffix(domain)
 | 
				
			||||||
 | 
							if got != want {
 | 
				
			||||||
 | 
								t.Errorf("%q: got %v, want %v", domain, got, want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var publicSuffixTestCases = []struct {
 | 
				
			||||||
 | 
						domain, want string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						// Empty string.
 | 
				
			||||||
 | 
						{"", ""},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .ao rules are:
 | 
				
			||||||
 | 
						// ao
 | 
				
			||||||
 | 
						// ed.ao
 | 
				
			||||||
 | 
						// gv.ao
 | 
				
			||||||
 | 
						// og.ao
 | 
				
			||||||
 | 
						// co.ao
 | 
				
			||||||
 | 
						// pb.ao
 | 
				
			||||||
 | 
						// it.ao
 | 
				
			||||||
 | 
						{"ao", "ao"},
 | 
				
			||||||
 | 
						{"www.ao", "ao"},
 | 
				
			||||||
 | 
						{"pb.ao", "pb.ao"},
 | 
				
			||||||
 | 
						{"www.pb.ao", "pb.ao"},
 | 
				
			||||||
 | 
						{"www.xxx.yyy.zzz.pb.ao", "pb.ao"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .ar rules are:
 | 
				
			||||||
 | 
						// ar
 | 
				
			||||||
 | 
						// com.ar
 | 
				
			||||||
 | 
						// edu.ar
 | 
				
			||||||
 | 
						// gob.ar
 | 
				
			||||||
 | 
						// gov.ar
 | 
				
			||||||
 | 
						// int.ar
 | 
				
			||||||
 | 
						// mil.ar
 | 
				
			||||||
 | 
						// net.ar
 | 
				
			||||||
 | 
						// org.ar
 | 
				
			||||||
 | 
						// tur.ar
 | 
				
			||||||
 | 
						// blogspot.com.ar
 | 
				
			||||||
 | 
						{"ar", "ar"},
 | 
				
			||||||
 | 
						{"www.ar", "ar"},
 | 
				
			||||||
 | 
						{"nic.ar", "ar"},
 | 
				
			||||||
 | 
						{"www.nic.ar", "ar"},
 | 
				
			||||||
 | 
						{"com.ar", "com.ar"},
 | 
				
			||||||
 | 
						{"www.com.ar", "com.ar"},
 | 
				
			||||||
 | 
						{"blogspot.com.ar", "blogspot.com.ar"},
 | 
				
			||||||
 | 
						{"www.blogspot.com.ar", "blogspot.com.ar"},
 | 
				
			||||||
 | 
						{"www.xxx.yyy.zzz.blogspot.com.ar", "blogspot.com.ar"},
 | 
				
			||||||
 | 
						{"logspot.com.ar", "com.ar"},
 | 
				
			||||||
 | 
						{"zlogspot.com.ar", "com.ar"},
 | 
				
			||||||
 | 
						{"zblogspot.com.ar", "com.ar"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .arpa rules are:
 | 
				
			||||||
 | 
						// arpa
 | 
				
			||||||
 | 
						// e164.arpa
 | 
				
			||||||
 | 
						// in-addr.arpa
 | 
				
			||||||
 | 
						// ip6.arpa
 | 
				
			||||||
 | 
						// iris.arpa
 | 
				
			||||||
 | 
						// uri.arpa
 | 
				
			||||||
 | 
						// urn.arpa
 | 
				
			||||||
 | 
						{"arpa", "arpa"},
 | 
				
			||||||
 | 
						{"www.arpa", "arpa"},
 | 
				
			||||||
 | 
						{"urn.arpa", "urn.arpa"},
 | 
				
			||||||
 | 
						{"www.urn.arpa", "urn.arpa"},
 | 
				
			||||||
 | 
						{"www.xxx.yyy.zzz.urn.arpa", "urn.arpa"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The relevant {kobe,kyoto}.jp rules are:
 | 
				
			||||||
 | 
						// jp
 | 
				
			||||||
 | 
						// *.kobe.jp
 | 
				
			||||||
 | 
						// !city.kobe.jp
 | 
				
			||||||
 | 
						// kyoto.jp
 | 
				
			||||||
 | 
						// ide.kyoto.jp
 | 
				
			||||||
 | 
						{"jp", "jp"},
 | 
				
			||||||
 | 
						{"kobe.jp", "jp"},
 | 
				
			||||||
 | 
						{"c.kobe.jp", "c.kobe.jp"},
 | 
				
			||||||
 | 
						{"b.c.kobe.jp", "c.kobe.jp"},
 | 
				
			||||||
 | 
						{"a.b.c.kobe.jp", "c.kobe.jp"},
 | 
				
			||||||
 | 
						{"city.kobe.jp", "kobe.jp"},
 | 
				
			||||||
 | 
						{"www.city.kobe.jp", "kobe.jp"},
 | 
				
			||||||
 | 
						{"kyoto.jp", "kyoto.jp"},
 | 
				
			||||||
 | 
						{"test.kyoto.jp", "kyoto.jp"},
 | 
				
			||||||
 | 
						{"ide.kyoto.jp", "ide.kyoto.jp"},
 | 
				
			||||||
 | 
						{"b.ide.kyoto.jp", "ide.kyoto.jp"},
 | 
				
			||||||
 | 
						{"a.b.ide.kyoto.jp", "ide.kyoto.jp"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .tw rules are:
 | 
				
			||||||
 | 
						// tw
 | 
				
			||||||
 | 
						// edu.tw
 | 
				
			||||||
 | 
						// gov.tw
 | 
				
			||||||
 | 
						// mil.tw
 | 
				
			||||||
 | 
						// com.tw
 | 
				
			||||||
 | 
						// net.tw
 | 
				
			||||||
 | 
						// org.tw
 | 
				
			||||||
 | 
						// idv.tw
 | 
				
			||||||
 | 
						// game.tw
 | 
				
			||||||
 | 
						// ebiz.tw
 | 
				
			||||||
 | 
						// club.tw
 | 
				
			||||||
 | 
						// 網路.tw (xn--zf0ao64a.tw)
 | 
				
			||||||
 | 
						// 組織.tw (xn--uc0atv.tw)
 | 
				
			||||||
 | 
						// 商業.tw (xn--czrw28b.tw)
 | 
				
			||||||
 | 
						// blogspot.tw
 | 
				
			||||||
 | 
						{"tw", "tw"},
 | 
				
			||||||
 | 
						{"aaa.tw", "tw"},
 | 
				
			||||||
 | 
						{"www.aaa.tw", "tw"},
 | 
				
			||||||
 | 
						{"xn--czrw28b.aaa.tw", "tw"},
 | 
				
			||||||
 | 
						{"edu.tw", "edu.tw"},
 | 
				
			||||||
 | 
						{"www.edu.tw", "edu.tw"},
 | 
				
			||||||
 | 
						{"xn--czrw28b.edu.tw", "edu.tw"},
 | 
				
			||||||
 | 
						{"xn--czrw28b.tw", "xn--czrw28b.tw"},
 | 
				
			||||||
 | 
						{"www.xn--czrw28b.tw", "xn--czrw28b.tw"},
 | 
				
			||||||
 | 
						{"xn--uc0atv.xn--czrw28b.tw", "xn--czrw28b.tw"},
 | 
				
			||||||
 | 
						{"xn--kpry57d.tw", "tw"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .uk rules are:
 | 
				
			||||||
 | 
						// uk
 | 
				
			||||||
 | 
						// ac.uk
 | 
				
			||||||
 | 
						// co.uk
 | 
				
			||||||
 | 
						// gov.uk
 | 
				
			||||||
 | 
						// ltd.uk
 | 
				
			||||||
 | 
						// me.uk
 | 
				
			||||||
 | 
						// net.uk
 | 
				
			||||||
 | 
						// nhs.uk
 | 
				
			||||||
 | 
						// org.uk
 | 
				
			||||||
 | 
						// plc.uk
 | 
				
			||||||
 | 
						// police.uk
 | 
				
			||||||
 | 
						// *.sch.uk
 | 
				
			||||||
 | 
						// blogspot.co.uk
 | 
				
			||||||
 | 
						{"uk", "uk"},
 | 
				
			||||||
 | 
						{"aaa.uk", "uk"},
 | 
				
			||||||
 | 
						{"www.aaa.uk", "uk"},
 | 
				
			||||||
 | 
						{"mod.uk", "uk"},
 | 
				
			||||||
 | 
						{"www.mod.uk", "uk"},
 | 
				
			||||||
 | 
						{"sch.uk", "uk"},
 | 
				
			||||||
 | 
						{"mod.sch.uk", "mod.sch.uk"},
 | 
				
			||||||
 | 
						{"www.sch.uk", "www.sch.uk"},
 | 
				
			||||||
 | 
						{"blogspot.co.uk", "blogspot.co.uk"},
 | 
				
			||||||
 | 
						{"blogspot.nic.uk", "uk"},
 | 
				
			||||||
 | 
						{"blogspot.sch.uk", "blogspot.sch.uk"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .рф rules are
 | 
				
			||||||
 | 
						// рф (xn--p1ai)
 | 
				
			||||||
 | 
						{"xn--p1ai", "xn--p1ai"},
 | 
				
			||||||
 | 
						{"aaa.xn--p1ai", "xn--p1ai"},
 | 
				
			||||||
 | 
						{"www.xxx.yyy.xn--p1ai", "xn--p1ai"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// The .bd rules are:
 | 
				
			||||||
 | 
						// *.bd
 | 
				
			||||||
 | 
						{"bd", "bd"},
 | 
				
			||||||
 | 
						{"www.bd", "www.bd"},
 | 
				
			||||||
 | 
						{"zzz.bd", "zzz.bd"},
 | 
				
			||||||
 | 
						{"www.zzz.bd", "zzz.bd"},
 | 
				
			||||||
 | 
						{"www.xxx.yyy.zzz.bd", "zzz.bd"},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// There are no .nosuchtld rules.
 | 
				
			||||||
 | 
						{"nosuchtld", "nosuchtld"},
 | 
				
			||||||
 | 
						{"foo.nosuchtld", "nosuchtld"},
 | 
				
			||||||
 | 
						{"bar.foo.nosuchtld", "nosuchtld"},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func BenchmarkPublicSuffix(b *testing.B) {
 | 
				
			||||||
 | 
						for i := 0; i < b.N; i++ {
 | 
				
			||||||
 | 
							for _, tc := range publicSuffixTestCases {
 | 
				
			||||||
 | 
								List.PublicSuffix(tc.domain)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestPublicSuffix(t *testing.T) {
 | 
				
			||||||
 | 
						for _, tc := range publicSuffixTestCases {
 | 
				
			||||||
 | 
							got := List.PublicSuffix(tc.domain)
 | 
				
			||||||
 | 
							if got != tc.want {
 | 
				
			||||||
 | 
								t.Errorf("%q: got %q, want %q", tc.domain, got, tc.want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestSlowPublicSuffix(t *testing.T) {
 | 
				
			||||||
 | 
						for _, tc := range publicSuffixTestCases {
 | 
				
			||||||
 | 
							got := slowPublicSuffix(tc.domain)
 | 
				
			||||||
 | 
							if got != tc.want {
 | 
				
			||||||
 | 
								t.Errorf("%q: got %q, want %q", tc.domain, got, tc.want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// slowPublicSuffix implements the canonical (but O(number of rules)) public
 | 
				
			||||||
 | 
					// suffix algorithm described at http://publicsuffix.org/list/.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// 1. Match domain against all rules and take note of the matching ones.
 | 
				
			||||||
 | 
					// 2. If no rules match, the prevailing rule is "*".
 | 
				
			||||||
 | 
					// 3. If more than one rule matches, the prevailing rule is the one which is an exception rule.
 | 
				
			||||||
 | 
					// 4. If there is no matching exception rule, the prevailing rule is the one with the most labels.
 | 
				
			||||||
 | 
					// 5. If the prevailing rule is a exception rule, modify it by removing the leftmost label.
 | 
				
			||||||
 | 
					// 6. The public suffix is the set of labels from the domain which directly match the labels of the prevailing rule (joined by dots).
 | 
				
			||||||
 | 
					// 7. The registered or registrable domain is the public suffix plus one additional label.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// This function returns the public suffix, not the registrable domain, and so
 | 
				
			||||||
 | 
					// it stops after step 6.
 | 
				
			||||||
 | 
					func slowPublicSuffix(domain string) string {
 | 
				
			||||||
 | 
						match := func(rulePart, domainPart string) bool {
 | 
				
			||||||
 | 
							switch rulePart[0] {
 | 
				
			||||||
 | 
							case '*':
 | 
				
			||||||
 | 
								return true
 | 
				
			||||||
 | 
							case '!':
 | 
				
			||||||
 | 
								return rulePart[1:] == domainPart
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return rulePart == domainPart
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						domainParts := strings.Split(domain, ".")
 | 
				
			||||||
 | 
						var matchingRules [][]string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					loop:
 | 
				
			||||||
 | 
						for _, rule := range rules {
 | 
				
			||||||
 | 
							ruleParts := strings.Split(rule, ".")
 | 
				
			||||||
 | 
							if len(domainParts) < len(ruleParts) {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							for i := range ruleParts {
 | 
				
			||||||
 | 
								rulePart := ruleParts[len(ruleParts)-1-i]
 | 
				
			||||||
 | 
								domainPart := domainParts[len(domainParts)-1-i]
 | 
				
			||||||
 | 
								if !match(rulePart, domainPart) {
 | 
				
			||||||
 | 
									continue loop
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							matchingRules = append(matchingRules, ruleParts)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(matchingRules) == 0 {
 | 
				
			||||||
 | 
							matchingRules = append(matchingRules, []string{"*"})
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							sort.Sort(byPriority(matchingRules))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						prevailing := matchingRules[0]
 | 
				
			||||||
 | 
						if prevailing[0][0] == '!' {
 | 
				
			||||||
 | 
							prevailing = prevailing[1:]
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if prevailing[0][0] == '*' {
 | 
				
			||||||
 | 
							replaced := domainParts[len(domainParts)-len(prevailing)]
 | 
				
			||||||
 | 
							prevailing = append([]string{replaced}, prevailing[1:]...)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return strings.Join(prevailing, ".")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type byPriority [][]string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (b byPriority) Len() int      { return len(b) }
 | 
				
			||||||
 | 
					func (b byPriority) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
 | 
				
			||||||
 | 
					func (b byPriority) Less(i, j int) bool {
 | 
				
			||||||
 | 
						if b[i][0][0] == '!' {
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if b[j][0][0] == '!' {
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return len(b[i]) > len(b[j])
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// eTLDPlusOneTestCases come from
 | 
				
			||||||
 | 
					// https://github.com/publicsuffix/list/blob/master/tests/test_psl.txt
 | 
				
			||||||
 | 
					var eTLDPlusOneTestCases = []struct {
 | 
				
			||||||
 | 
						domain, want string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						// Empty input.
 | 
				
			||||||
 | 
						{"", ""},
 | 
				
			||||||
 | 
						// Unlisted TLD.
 | 
				
			||||||
 | 
						{"example", ""},
 | 
				
			||||||
 | 
						{"example.example", "example.example"},
 | 
				
			||||||
 | 
						{"b.example.example", "example.example"},
 | 
				
			||||||
 | 
						{"a.b.example.example", "example.example"},
 | 
				
			||||||
 | 
						// TLD with only 1 rule.
 | 
				
			||||||
 | 
						{"biz", ""},
 | 
				
			||||||
 | 
						{"domain.biz", "domain.biz"},
 | 
				
			||||||
 | 
						{"b.domain.biz", "domain.biz"},
 | 
				
			||||||
 | 
						{"a.b.domain.biz", "domain.biz"},
 | 
				
			||||||
 | 
						// TLD with some 2-level rules.
 | 
				
			||||||
 | 
						{"com", ""},
 | 
				
			||||||
 | 
						{"example.com", "example.com"},
 | 
				
			||||||
 | 
						{"b.example.com", "example.com"},
 | 
				
			||||||
 | 
						{"a.b.example.com", "example.com"},
 | 
				
			||||||
 | 
						{"uk.com", ""},
 | 
				
			||||||
 | 
						{"example.uk.com", "example.uk.com"},
 | 
				
			||||||
 | 
						{"b.example.uk.com", "example.uk.com"},
 | 
				
			||||||
 | 
						{"a.b.example.uk.com", "example.uk.com"},
 | 
				
			||||||
 | 
						{"test.ac", "test.ac"},
 | 
				
			||||||
 | 
						// TLD with only 1 (wildcard) rule.
 | 
				
			||||||
 | 
						{"mm", ""},
 | 
				
			||||||
 | 
						{"c.mm", ""},
 | 
				
			||||||
 | 
						{"b.c.mm", "b.c.mm"},
 | 
				
			||||||
 | 
						{"a.b.c.mm", "b.c.mm"},
 | 
				
			||||||
 | 
						// More complex TLD.
 | 
				
			||||||
 | 
						{"jp", ""},
 | 
				
			||||||
 | 
						{"test.jp", "test.jp"},
 | 
				
			||||||
 | 
						{"www.test.jp", "test.jp"},
 | 
				
			||||||
 | 
						{"ac.jp", ""},
 | 
				
			||||||
 | 
						{"test.ac.jp", "test.ac.jp"},
 | 
				
			||||||
 | 
						{"www.test.ac.jp", "test.ac.jp"},
 | 
				
			||||||
 | 
						{"kyoto.jp", ""},
 | 
				
			||||||
 | 
						{"test.kyoto.jp", "test.kyoto.jp"},
 | 
				
			||||||
 | 
						{"ide.kyoto.jp", ""},
 | 
				
			||||||
 | 
						{"b.ide.kyoto.jp", "b.ide.kyoto.jp"},
 | 
				
			||||||
 | 
						{"a.b.ide.kyoto.jp", "b.ide.kyoto.jp"},
 | 
				
			||||||
 | 
						{"c.kobe.jp", ""},
 | 
				
			||||||
 | 
						{"b.c.kobe.jp", "b.c.kobe.jp"},
 | 
				
			||||||
 | 
						{"a.b.c.kobe.jp", "b.c.kobe.jp"},
 | 
				
			||||||
 | 
						{"city.kobe.jp", "city.kobe.jp"},
 | 
				
			||||||
 | 
						{"www.city.kobe.jp", "city.kobe.jp"},
 | 
				
			||||||
 | 
						// TLD with a wildcard rule and exceptions.
 | 
				
			||||||
 | 
						{"ck", ""},
 | 
				
			||||||
 | 
						{"test.ck", ""},
 | 
				
			||||||
 | 
						{"b.test.ck", "b.test.ck"},
 | 
				
			||||||
 | 
						{"a.b.test.ck", "b.test.ck"},
 | 
				
			||||||
 | 
						{"www.ck", "www.ck"},
 | 
				
			||||||
 | 
						{"www.www.ck", "www.ck"},
 | 
				
			||||||
 | 
						// US K12.
 | 
				
			||||||
 | 
						{"us", ""},
 | 
				
			||||||
 | 
						{"test.us", "test.us"},
 | 
				
			||||||
 | 
						{"www.test.us", "test.us"},
 | 
				
			||||||
 | 
						{"ak.us", ""},
 | 
				
			||||||
 | 
						{"test.ak.us", "test.ak.us"},
 | 
				
			||||||
 | 
						{"www.test.ak.us", "test.ak.us"},
 | 
				
			||||||
 | 
						{"k12.ak.us", ""},
 | 
				
			||||||
 | 
						{"test.k12.ak.us", "test.k12.ak.us"},
 | 
				
			||||||
 | 
						{"www.test.k12.ak.us", "test.k12.ak.us"},
 | 
				
			||||||
 | 
						// Punycoded IDN labels
 | 
				
			||||||
 | 
						{"xn--85x722f.com.cn", "xn--85x722f.com.cn"},
 | 
				
			||||||
 | 
						{"xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn"},
 | 
				
			||||||
 | 
						{"www.xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn"},
 | 
				
			||||||
 | 
						{"shishi.xn--55qx5d.cn", "shishi.xn--55qx5d.cn"},
 | 
				
			||||||
 | 
						{"xn--55qx5d.cn", ""},
 | 
				
			||||||
 | 
						{"xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s"},
 | 
				
			||||||
 | 
						{"www.xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s"},
 | 
				
			||||||
 | 
						{"shishi.xn--fiqs8s", "shishi.xn--fiqs8s"},
 | 
				
			||||||
 | 
						{"xn--fiqs8s", ""},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestEffectiveTLDPlusOne(t *testing.T) {
 | 
				
			||||||
 | 
						for _, tc := range eTLDPlusOneTestCases {
 | 
				
			||||||
 | 
							got, _ := EffectiveTLDPlusOne(tc.domain)
 | 
				
			||||||
 | 
							if got != tc.want {
 | 
				
			||||||
 | 
								t.Errorf("%q: got %q, want %q", tc.domain, got, tc.want)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										17308
									
								
								vendor/golang.org/x/net/publicsuffix/table_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										17308
									
								
								vendor/golang.org/x/net/publicsuffix/table_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1326
									
								
								vendor/gopkg.in/yaml.v2/decode_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1326
									
								
								vendor/gopkg.in/yaml.v2/decode_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										595
									
								
								vendor/gopkg.in/yaml.v2/encode_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										595
									
								
								vendor/gopkg.in/yaml.v2/encode_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,595 @@
 | 
				
			|||||||
 | 
					package yaml_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"bytes"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"math"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						. "gopkg.in/check.v1"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v2"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var marshalIntTest = 123
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var marshalTests = []struct {
 | 
				
			||||||
 | 
						value interface{}
 | 
				
			||||||
 | 
						data  string
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							nil,
 | 
				
			||||||
 | 
							"null\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							(*marshalerType)(nil),
 | 
				
			||||||
 | 
							"null\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct{}{},
 | 
				
			||||||
 | 
							"{}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]string{"v": "hi"},
 | 
				
			||||||
 | 
							"v: hi\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": "hi"},
 | 
				
			||||||
 | 
							"v: hi\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]string{"v": "true"},
 | 
				
			||||||
 | 
							"v: \"true\"\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]string{"v": "false"},
 | 
				
			||||||
 | 
							"v: \"false\"\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": true},
 | 
				
			||||||
 | 
							"v: true\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": false},
 | 
				
			||||||
 | 
							"v: false\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": 10},
 | 
				
			||||||
 | 
							"v: 10\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": -10},
 | 
				
			||||||
 | 
							"v: -10\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]uint{"v": 42},
 | 
				
			||||||
 | 
							"v: 42\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": int64(4294967296)},
 | 
				
			||||||
 | 
							"v: 4294967296\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]int64{"v": int64(4294967296)},
 | 
				
			||||||
 | 
							"v: 4294967296\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]uint64{"v": 4294967296},
 | 
				
			||||||
 | 
							"v: 4294967296\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": "10"},
 | 
				
			||||||
 | 
							"v: \"10\"\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": 0.1},
 | 
				
			||||||
 | 
							"v: 0.1\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": float64(0.1)},
 | 
				
			||||||
 | 
							"v: 0.1\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": float32(0.99)},
 | 
				
			||||||
 | 
							"v: 0.99\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": -0.1},
 | 
				
			||||||
 | 
							"v: -0.1\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": math.Inf(+1)},
 | 
				
			||||||
 | 
							"v: .inf\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": math.Inf(-1)},
 | 
				
			||||||
 | 
							"v: -.inf\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": math.NaN()},
 | 
				
			||||||
 | 
							"v: .nan\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": nil},
 | 
				
			||||||
 | 
							"v: null\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"v": ""},
 | 
				
			||||||
 | 
							"v: \"\"\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string][]string{"v": []string{"A", "B"}},
 | 
				
			||||||
 | 
							"v:\n- A\n- B\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string][]string{"v": []string{"A", "B\nC"}},
 | 
				
			||||||
 | 
							"v:\n- A\n- |-\n  B\n  C\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string][]interface{}{"v": []interface{}{"A", 1, map[string][]int{"B": []int{2, 3}}}},
 | 
				
			||||||
 | 
							"v:\n- A\n- 1\n- B:\n  - 2\n  - 3\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
 | 
				
			||||||
 | 
							"a:\n  b: c\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]interface{}{"a": "-"},
 | 
				
			||||||
 | 
							"a: '-'\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Simple values.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&marshalIntTest,
 | 
				
			||||||
 | 
							"123\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Structures
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct{ Hello string }{"world"},
 | 
				
			||||||
 | 
							"hello: world\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A struct {
 | 
				
			||||||
 | 
									B string
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}{struct{ B string }{"c"}},
 | 
				
			||||||
 | 
							"a:\n  b: c\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A *struct {
 | 
				
			||||||
 | 
									B string
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}{&struct{ B string }{"c"}},
 | 
				
			||||||
 | 
							"a:\n  b: c\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A *struct {
 | 
				
			||||||
 | 
									B string
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}{},
 | 
				
			||||||
 | 
							"a: null\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct{ A int }{1},
 | 
				
			||||||
 | 
							"a: 1\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct{ A []int }{[]int{1, 2}},
 | 
				
			||||||
 | 
							"a:\n- 1\n- 2\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct{ A [2]int }{[2]int{1, 2}},
 | 
				
			||||||
 | 
							"a:\n- 1\n- 2\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								B int "a"
 | 
				
			||||||
 | 
							}{1},
 | 
				
			||||||
 | 
							"a: 1\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct{ A bool }{true},
 | 
				
			||||||
 | 
							"a: true\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Conditional flag
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A int "a,omitempty"
 | 
				
			||||||
 | 
								B int "b,omitempty"
 | 
				
			||||||
 | 
							}{1, 0},
 | 
				
			||||||
 | 
							"a: 1\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A int "a,omitempty"
 | 
				
			||||||
 | 
								B int "b,omitempty"
 | 
				
			||||||
 | 
							}{0, 0},
 | 
				
			||||||
 | 
							"{}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A *struct{ X, y int } "a,omitempty,flow"
 | 
				
			||||||
 | 
							}{&struct{ X, y int }{1, 2}},
 | 
				
			||||||
 | 
							"a: {x: 1}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A *struct{ X, y int } "a,omitempty,flow"
 | 
				
			||||||
 | 
							}{nil},
 | 
				
			||||||
 | 
							"{}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A *struct{ X, y int } "a,omitempty,flow"
 | 
				
			||||||
 | 
							}{&struct{ X, y int }{}},
 | 
				
			||||||
 | 
							"a: {x: 0}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A struct{ X, y int } "a,omitempty,flow"
 | 
				
			||||||
 | 
							}{struct{ X, y int }{1, 2}},
 | 
				
			||||||
 | 
							"a: {x: 1}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A struct{ X, y int } "a,omitempty,flow"
 | 
				
			||||||
 | 
							}{struct{ X, y int }{0, 1}},
 | 
				
			||||||
 | 
							"{}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A float64 "a,omitempty"
 | 
				
			||||||
 | 
								B float64 "b,omitempty"
 | 
				
			||||||
 | 
							}{1, 0},
 | 
				
			||||||
 | 
							"a: 1\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								T1 time.Time  "t1,omitempty"
 | 
				
			||||||
 | 
								T2 time.Time  "t2,omitempty"
 | 
				
			||||||
 | 
								T3 *time.Time "t3,omitempty"
 | 
				
			||||||
 | 
								T4 *time.Time "t4,omitempty"
 | 
				
			||||||
 | 
							}{
 | 
				
			||||||
 | 
								T2: time.Date(2018, 1, 9, 10, 40, 47, 0, time.UTC),
 | 
				
			||||||
 | 
								T4: newTime(time.Date(2098, 1, 9, 10, 40, 47, 0, time.UTC)),
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"t2: 2018-01-09T10:40:47Z\nt4: 2098-01-09T10:40:47Z\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						// Nil interface that implements Marshaler.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]yaml.Marshaler{
 | 
				
			||||||
 | 
								"a": nil,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							"a: null\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Flow flag
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A []int "a,flow"
 | 
				
			||||||
 | 
							}{[]int{1, 2}},
 | 
				
			||||||
 | 
							"a: [1, 2]\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A map[string]string "a,flow"
 | 
				
			||||||
 | 
							}{map[string]string{"b": "c", "d": "e"}},
 | 
				
			||||||
 | 
							"a: {b: c, d: e}\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A struct {
 | 
				
			||||||
 | 
									B, D string
 | 
				
			||||||
 | 
								} "a,flow"
 | 
				
			||||||
 | 
							}{struct{ B, D string }{"c", "e"}},
 | 
				
			||||||
 | 
							"a: {b: c, d: e}\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Unexported field
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								u int
 | 
				
			||||||
 | 
								A int
 | 
				
			||||||
 | 
							}{0, 1},
 | 
				
			||||||
 | 
							"a: 1\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Ignored field
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A int
 | 
				
			||||||
 | 
								B int "-"
 | 
				
			||||||
 | 
							}{1, 2},
 | 
				
			||||||
 | 
							"a: 1\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Struct inlining
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A int
 | 
				
			||||||
 | 
								C inlineB `yaml:",inline"`
 | 
				
			||||||
 | 
							}{1, inlineB{2, inlineC{3}}},
 | 
				
			||||||
 | 
							"a: 1\nb: 2\nc: 3\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Map inlining
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&struct {
 | 
				
			||||||
 | 
								A int
 | 
				
			||||||
 | 
								C map[string]int `yaml:",inline"`
 | 
				
			||||||
 | 
							}{1, map[string]int{"b": 2, "c": 3}},
 | 
				
			||||||
 | 
							"a: 1\nb: 2\nc: 3\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Duration
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]time.Duration{"a": 3 * time.Second},
 | 
				
			||||||
 | 
							"a: 3s\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Issue #24: bug in map merging logic.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "<foo>"},
 | 
				
			||||||
 | 
							"a: <foo>\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Issue #34: marshal unsupported base 60 floats quoted for compatibility
 | 
				
			||||||
 | 
						// with old YAML 1.1 parsers.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "1:1"},
 | 
				
			||||||
 | 
							"a: \"1:1\"\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Binary data.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "\x00"},
 | 
				
			||||||
 | 
							"a: \"\\0\"\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]string{"a": "\x80\x81\x82"},
 | 
				
			||||||
 | 
							"a: !!binary gIGC\n",
 | 
				
			||||||
 | 
						}, {
 | 
				
			||||||
 | 
							map[string]string{"a": strings.Repeat("\x90", 54)},
 | 
				
			||||||
 | 
							"a: !!binary |\n  " + strings.Repeat("kJCQ", 17) + "kJ\n  CQ\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Ordered maps.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							&yaml.MapSlice{{"b", 2}, {"a", 1}, {"d", 4}, {"c", 3}, {"sub", yaml.MapSlice{{"e", 5}}}},
 | 
				
			||||||
 | 
							"b: 2\na: 1\nd: 4\nc: 3\nsub:\n  e: 5\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Encode unicode as utf-8 rather than in escaped form.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "你好"},
 | 
				
			||||||
 | 
							"a: 你好\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Support encoding.TextMarshaler.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]net.IP{"a": net.IPv4(1, 2, 3, 4)},
 | 
				
			||||||
 | 
							"a: 1.2.3.4\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						// time.Time gets a timestamp tag.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]time.Time{"a": time.Date(2015, 2, 24, 18, 19, 39, 0, time.UTC)},
 | 
				
			||||||
 | 
							"a: 2015-02-24T18:19:39Z\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]*time.Time{"a": newTime(time.Date(2015, 2, 24, 18, 19, 39, 0, time.UTC))},
 | 
				
			||||||
 | 
							"a: 2015-02-24T18:19:39Z\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// This is confirmed to be properly decoded in Python (libyaml) without a timestamp tag.
 | 
				
			||||||
 | 
							map[string]time.Time{"a": time.Date(2015, 2, 24, 18, 19, 39, 123456789, time.FixedZone("FOO", -3*60*60))},
 | 
				
			||||||
 | 
							"a: 2015-02-24T18:19:39.123456789-03:00\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						// Ensure timestamp-like strings are quoted.
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "2015-02-24T18:19:39Z"},
 | 
				
			||||||
 | 
							"a: \"2015-02-24T18:19:39Z\"\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Ensure strings containing ": " are quoted (reported as PR #43, but not reproducible).
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "b: c"},
 | 
				
			||||||
 | 
							"a: 'b: c'\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Containing hash mark ('#') in string should be quoted
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "Hello #comment"},
 | 
				
			||||||
 | 
							"a: 'Hello #comment'\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							map[string]string{"a": "你好 #comment"},
 | 
				
			||||||
 | 
							"a: '你好 #comment'\n",
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestMarshal(c *C) {
 | 
				
			||||||
 | 
						defer os.Setenv("TZ", os.Getenv("TZ"))
 | 
				
			||||||
 | 
						os.Setenv("TZ", "UTC")
 | 
				
			||||||
 | 
						for i, item := range marshalTests {
 | 
				
			||||||
 | 
							c.Logf("test %d: %q", i, item.data)
 | 
				
			||||||
 | 
							data, err := yaml.Marshal(item.value)
 | 
				
			||||||
 | 
							c.Assert(err, IsNil)
 | 
				
			||||||
 | 
							c.Assert(string(data), Equals, item.data)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestEncoderSingleDocument(c *C) {
 | 
				
			||||||
 | 
						for i, item := range marshalTests {
 | 
				
			||||||
 | 
							c.Logf("test %d. %q", i, item.data)
 | 
				
			||||||
 | 
							var buf bytes.Buffer
 | 
				
			||||||
 | 
							enc := yaml.NewEncoder(&buf)
 | 
				
			||||||
 | 
							err := enc.Encode(item.value)
 | 
				
			||||||
 | 
							c.Assert(err, Equals, nil)
 | 
				
			||||||
 | 
							err = enc.Close()
 | 
				
			||||||
 | 
							c.Assert(err, Equals, nil)
 | 
				
			||||||
 | 
							c.Assert(buf.String(), Equals, item.data)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestEncoderMultipleDocuments(c *C) {
 | 
				
			||||||
 | 
						var buf bytes.Buffer
 | 
				
			||||||
 | 
						enc := yaml.NewEncoder(&buf)
 | 
				
			||||||
 | 
						err := enc.Encode(map[string]string{"a": "b"})
 | 
				
			||||||
 | 
						c.Assert(err, Equals, nil)
 | 
				
			||||||
 | 
						err = enc.Encode(map[string]string{"c": "d"})
 | 
				
			||||||
 | 
						c.Assert(err, Equals, nil)
 | 
				
			||||||
 | 
						err = enc.Close()
 | 
				
			||||||
 | 
						c.Assert(err, Equals, nil)
 | 
				
			||||||
 | 
						c.Assert(buf.String(), Equals, "a: b\n---\nc: d\n")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestEncoderWriteError(c *C) {
 | 
				
			||||||
 | 
						enc := yaml.NewEncoder(errorWriter{})
 | 
				
			||||||
 | 
						err := enc.Encode(map[string]string{"a": "b"})
 | 
				
			||||||
 | 
						c.Assert(err, ErrorMatches, `yaml: write error: some write error`) // Data not flushed yet
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type errorWriter struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (errorWriter) Write([]byte) (int, error) {
 | 
				
			||||||
 | 
						return 0, fmt.Errorf("some write error")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var marshalErrorTests = []struct {
 | 
				
			||||||
 | 
						value interface{}
 | 
				
			||||||
 | 
						error string
 | 
				
			||||||
 | 
						panic string
 | 
				
			||||||
 | 
					}{{
 | 
				
			||||||
 | 
						value: &struct {
 | 
				
			||||||
 | 
							B       int
 | 
				
			||||||
 | 
							inlineB ",inline"
 | 
				
			||||||
 | 
						}{1, inlineB{2, inlineC{3}}},
 | 
				
			||||||
 | 
						panic: `Duplicated key 'b' in struct struct \{ B int; .*`,
 | 
				
			||||||
 | 
					}, {
 | 
				
			||||||
 | 
						value: &struct {
 | 
				
			||||||
 | 
							A int
 | 
				
			||||||
 | 
							B map[string]int ",inline"
 | 
				
			||||||
 | 
						}{1, map[string]int{"a": 2}},
 | 
				
			||||||
 | 
						panic: `Can't have key "a" in inlined map; conflicts with struct field`,
 | 
				
			||||||
 | 
					}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestMarshalErrors(c *C) {
 | 
				
			||||||
 | 
						for _, item := range marshalErrorTests {
 | 
				
			||||||
 | 
							if item.panic != "" {
 | 
				
			||||||
 | 
								c.Assert(func() { yaml.Marshal(item.value) }, PanicMatches, item.panic)
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								_, err := yaml.Marshal(item.value)
 | 
				
			||||||
 | 
								c.Assert(err, ErrorMatches, item.error)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestMarshalTypeCache(c *C) {
 | 
				
			||||||
 | 
						var data []byte
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						func() {
 | 
				
			||||||
 | 
							type T struct{ A int }
 | 
				
			||||||
 | 
							data, err = yaml.Marshal(&T{})
 | 
				
			||||||
 | 
							c.Assert(err, IsNil)
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
						func() {
 | 
				
			||||||
 | 
							type T struct{ B int }
 | 
				
			||||||
 | 
							data, err = yaml.Marshal(&T{})
 | 
				
			||||||
 | 
							c.Assert(err, IsNil)
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
						c.Assert(string(data), Equals, "b: 0\n")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var marshalerTests = []struct {
 | 
				
			||||||
 | 
						data  string
 | 
				
			||||||
 | 
						value interface{}
 | 
				
			||||||
 | 
					}{
 | 
				
			||||||
 | 
						{"_:\n  hi: there\n", map[interface{}]interface{}{"hi": "there"}},
 | 
				
			||||||
 | 
						{"_:\n- 1\n- A\n", []interface{}{1, "A"}},
 | 
				
			||||||
 | 
						{"_: 10\n", 10},
 | 
				
			||||||
 | 
						{"_: null\n", nil},
 | 
				
			||||||
 | 
						{"_: BAR!\n", "BAR!"},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type marshalerType struct {
 | 
				
			||||||
 | 
						value interface{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (o marshalerType) MarshalText() ([]byte, error) {
 | 
				
			||||||
 | 
						panic("MarshalText called on type with MarshalYAML")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (o marshalerType) MarshalYAML() (interface{}, error) {
 | 
				
			||||||
 | 
						return o.value, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type marshalerValue struct {
 | 
				
			||||||
 | 
						Field marshalerType "_"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestMarshaler(c *C) {
 | 
				
			||||||
 | 
						for _, item := range marshalerTests {
 | 
				
			||||||
 | 
							obj := &marshalerValue{}
 | 
				
			||||||
 | 
							obj.Field.value = item.value
 | 
				
			||||||
 | 
							data, err := yaml.Marshal(obj)
 | 
				
			||||||
 | 
							c.Assert(err, IsNil)
 | 
				
			||||||
 | 
							c.Assert(string(data), Equals, string(item.data))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestMarshalerWholeDocument(c *C) {
 | 
				
			||||||
 | 
						obj := &marshalerType{}
 | 
				
			||||||
 | 
						obj.value = map[string]string{"hello": "world!"}
 | 
				
			||||||
 | 
						data, err := yaml.Marshal(obj)
 | 
				
			||||||
 | 
						c.Assert(err, IsNil)
 | 
				
			||||||
 | 
						c.Assert(string(data), Equals, "hello: world!\n")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type failingMarshaler struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ft *failingMarshaler) MarshalYAML() (interface{}, error) {
 | 
				
			||||||
 | 
						return nil, failingErr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestMarshalerError(c *C) {
 | 
				
			||||||
 | 
						_, err := yaml.Marshal(&failingMarshaler{})
 | 
				
			||||||
 | 
						c.Assert(err, Equals, failingErr)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *S) TestSortedOutput(c *C) {
 | 
				
			||||||
 | 
						order := []interface{}{
 | 
				
			||||||
 | 
							false,
 | 
				
			||||||
 | 
							true,
 | 
				
			||||||
 | 
							1,
 | 
				
			||||||
 | 
							uint(1),
 | 
				
			||||||
 | 
							1.0,
 | 
				
			||||||
 | 
							1.1,
 | 
				
			||||||
 | 
							1.2,
 | 
				
			||||||
 | 
							2,
 | 
				
			||||||
 | 
							uint(2),
 | 
				
			||||||
 | 
							2.0,
 | 
				
			||||||
 | 
							2.1,
 | 
				
			||||||
 | 
							"",
 | 
				
			||||||
 | 
							".1",
 | 
				
			||||||
 | 
							".2",
 | 
				
			||||||
 | 
							".a",
 | 
				
			||||||
 | 
							"1",
 | 
				
			||||||
 | 
							"2",
 | 
				
			||||||
 | 
							"a!10",
 | 
				
			||||||
 | 
							"a/0001",
 | 
				
			||||||
 | 
							"a/002",
 | 
				
			||||||
 | 
							"a/3",
 | 
				
			||||||
 | 
							"a/10",
 | 
				
			||||||
 | 
							"a/11",
 | 
				
			||||||
 | 
							"a/0012",
 | 
				
			||||||
 | 
							"a/100",
 | 
				
			||||||
 | 
							"a~10",
 | 
				
			||||||
 | 
							"ab/1",
 | 
				
			||||||
 | 
							"b/1",
 | 
				
			||||||
 | 
							"b/01",
 | 
				
			||||||
 | 
							"b/2",
 | 
				
			||||||
 | 
							"b/02",
 | 
				
			||||||
 | 
							"b/3",
 | 
				
			||||||
 | 
							"b/03",
 | 
				
			||||||
 | 
							"b1",
 | 
				
			||||||
 | 
							"b01",
 | 
				
			||||||
 | 
							"b3",
 | 
				
			||||||
 | 
							"c2.10",
 | 
				
			||||||
 | 
							"c10.2",
 | 
				
			||||||
 | 
							"d1",
 | 
				
			||||||
 | 
							"d7",
 | 
				
			||||||
 | 
							"d7abc",
 | 
				
			||||||
 | 
							"d12",
 | 
				
			||||||
 | 
							"d12a",
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						m := make(map[interface{}]int)
 | 
				
			||||||
 | 
						for _, k := range order {
 | 
				
			||||||
 | 
							m[k] = 1
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						data, err := yaml.Marshal(m)
 | 
				
			||||||
 | 
						c.Assert(err, IsNil)
 | 
				
			||||||
 | 
						out := "\n" + string(data)
 | 
				
			||||||
 | 
						last := 0
 | 
				
			||||||
 | 
						for i, k := range order {
 | 
				
			||||||
 | 
							repr := fmt.Sprint(k)
 | 
				
			||||||
 | 
							if s, ok := k.(string); ok {
 | 
				
			||||||
 | 
								if _, err = strconv.ParseFloat(repr, 32); s == "" || err == nil {
 | 
				
			||||||
 | 
									repr = `"` + repr + `"`
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							index := strings.Index(out, "\n"+repr+":")
 | 
				
			||||||
 | 
							if index == -1 {
 | 
				
			||||||
 | 
								c.Fatalf("%#v is not in the output: %#v", k, out)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if index < last {
 | 
				
			||||||
 | 
								c.Fatalf("%#v was generated before %#v: %q", k, order[i-1], out)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							last = index
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newTime(t time.Time) *time.Time {
 | 
				
			||||||
 | 
						return &t
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										41
									
								
								vendor/gopkg.in/yaml.v2/example_embedded_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								vendor/gopkg.in/yaml.v2/example_embedded_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					package yaml_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v2"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// An example showing how to unmarshal embedded
 | 
				
			||||||
 | 
					// structs from YAML.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type StructA struct {
 | 
				
			||||||
 | 
						A string `yaml:"a"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type StructB struct {
 | 
				
			||||||
 | 
						// Embedded structs are not treated as embedded in YAML by default. To do that,
 | 
				
			||||||
 | 
						// add the ",inline" annotation below
 | 
				
			||||||
 | 
						StructA `yaml:",inline"`
 | 
				
			||||||
 | 
						B       string `yaml:"b"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var data = `
 | 
				
			||||||
 | 
					a: a string from struct A
 | 
				
			||||||
 | 
					b: a string from struct B
 | 
				
			||||||
 | 
					`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ExampleUnmarshal_embedded() {
 | 
				
			||||||
 | 
						var b StructB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err := yaml.Unmarshal([]byte(data), &b)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Fatalf("cannot unmarshal data: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						fmt.Println(b.A)
 | 
				
			||||||
 | 
						fmt.Println(b.B)
 | 
				
			||||||
 | 
						// Output:
 | 
				
			||||||
 | 
						// a string from struct A
 | 
				
			||||||
 | 
						// a string from struct B
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										12
									
								
								vendor/gopkg.in/yaml.v2/suite_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								vendor/gopkg.in/yaml.v2/suite_test.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					package yaml_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						. "gopkg.in/check.v1"
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func Test(t *testing.T) { TestingT(t) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type S struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _ = Suite(&S{})
 | 
				
			||||||
							
								
								
									
										14
									
								
								vendor/vendor.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								vendor/vendor.json
									
									
									
									
										vendored
									
									
								
							@@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	"comment": "",
 | 
						"comment": "",
 | 
				
			||||||
	"ignore": "test",
 | 
						"ignore": "",
 | 
				
			||||||
	"package": [
 | 
						"package": [
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "dvabztWVQX8f6oMLRyv4dLH+TGY=",
 | 
								"checksumSHA1": "dvabztWVQX8f6oMLRyv4dLH+TGY=",
 | 
				
			||||||
@@ -10,19 +10,19 @@
 | 
				
			|||||||
			"revisionTime": "2018-05-26T10:32:01Z"
 | 
								"revisionTime": "2018-05-26T10:32:01Z"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "5BP5xofo0GoFi6FtgqFFbmHyUKI=",
 | 
								"checksumSHA1": "gWgIakfod/4S6BjXj/OQ547R3gI=",
 | 
				
			||||||
			"path": "github.com/fatih/structs",
 | 
								"path": "github.com/fatih/structs",
 | 
				
			||||||
			"revision": "ebf56d35bba727c68ac77f56f2fcf90b181851aa",
 | 
								"revision": "ebf56d35bba727c68ac77f56f2fcf90b181851aa",
 | 
				
			||||||
			"revisionTime": "2018-01-23T06:50:59Z"
 | 
								"revisionTime": "2018-01-23T06:50:59Z"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "p3IB18uJRs4dL2K5yx24MrLYE9A=",
 | 
								"checksumSHA1": "aDjb3mG2PnOgRgQXVXBxzPNc9I0=",
 | 
				
			||||||
			"path": "github.com/google/go-querystring/query",
 | 
								"path": "github.com/google/go-querystring/query",
 | 
				
			||||||
			"revision": "53e6ce116135b80d037921a7fdd5138cf32d7a8a",
 | 
								"revision": "53e6ce116135b80d037921a7fdd5138cf32d7a8a",
 | 
				
			||||||
			"revisionTime": "2017-01-11T10:11:55Z"
 | 
								"revisionTime": "2017-01-11T10:11:55Z"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "e3krTtxeGeDTyWRkZC7BOYfexCw=",
 | 
								"checksumSHA1": "5q9WATK6eefsC/zUKQpq+lOw3Xo=",
 | 
				
			||||||
			"path": "github.com/levigross/grequests",
 | 
								"path": "github.com/levigross/grequests",
 | 
				
			||||||
			"revision": "bf9788368aa04abf510962fd0fb0d8e4b74396cc",
 | 
								"revision": "bf9788368aa04abf510962fd0fb0d8e4b74396cc",
 | 
				
			||||||
			"revisionTime": "2017-10-09T01:03:47Z"
 | 
								"revisionTime": "2017-10-09T01:03:47Z"
 | 
				
			||||||
@@ -35,19 +35,19 @@
 | 
				
			|||||||
			"revisionTime": "2018-05-26T10:32:01Z"
 | 
								"revisionTime": "2018-05-26T10:32:01Z"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "6LwXZI7kXm1C0h4Ui0Y52p9uQhk=",
 | 
								"checksumSHA1": "OMAKAu5bUX4xb+i9F3jgl3Ndvog=",
 | 
				
			||||||
			"path": "github.com/stretchr/testify/assert",
 | 
								"path": "github.com/stretchr/testify/assert",
 | 
				
			||||||
			"revision": "ef2d0154048f21662542b56ba1d1bd9f82278d2b",
 | 
								"revision": "ef2d0154048f21662542b56ba1d1bd9f82278d2b",
 | 
				
			||||||
			"revisionTime": "2018-05-26T10:32:01Z"
 | 
								"revisionTime": "2018-05-26T10:32:01Z"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "bMhIYx4Cgl6jit4Y2PW+dKsrFuU=",
 | 
								"checksumSHA1": "7HLXWSV0m0jwS9qU0Nlmu285dyM=",
 | 
				
			||||||
			"path": "golang.org/x/net/publicsuffix",
 | 
								"path": "golang.org/x/net/publicsuffix",
 | 
				
			||||||
			"revision": "4cb1c02c05b0e749b0365f61ae859a8e0cfceed9",
 | 
								"revision": "4cb1c02c05b0e749b0365f61ae859a8e0cfceed9",
 | 
				
			||||||
			"revisionTime": "2018-06-28T17:19:52Z"
 | 
								"revisionTime": "2018-06-28T17:19:52Z"
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			"checksumSHA1": "ZSWoOPUNRr5+3dhkLK3C4cZAQPk=",
 | 
								"checksumSHA1": "3qx1s/G7sJ0wjWpW3bhLWuCFwTw=",
 | 
				
			||||||
			"path": "gopkg.in/yaml.v2",
 | 
								"path": "gopkg.in/yaml.v2",
 | 
				
			||||||
			"revision": "5420a8b6744d3b0345ab293f6fcba19c978f1183",
 | 
								"revision": "5420a8b6744d3b0345ab293f6fcba19c978f1183",
 | 
				
			||||||
			"revisionTime": "2018-03-28T19:50:20Z"
 | 
								"revisionTime": "2018-03-28T19:50:20Z"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user