當前位置: 首頁>>代碼示例>>Golang>>正文


Golang TestServer.Get方法代碼示例

本文整理匯總了Golang中github.com/nucleartide/request.TestServer.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang TestServer.Get方法的具體用法?Golang TestServer.Get怎麽用?Golang TestServer.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/nucleartide/request.TestServer的用法示例。


在下文中一共展示了TestServer.Get方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestActiveHeader

func TestActiveHeader(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	testcases := []struct {
		Path string
		Link string
	}{
		{"/about", "About"},
		{"/contact", "Contact"},
		{"/help", "Help"},
		{"/", "Home"},
	}

	It("should highlight the correct header link", func() {
		for _, test := range testcases {
			ctx := record.Get(test.Path)
			reader := strings.NewReader(ctx.ResponseRecorder.Body.String())
			doc, err := goquery.NewDocumentFromReader(reader)
			if err != nil {
				t.Fatal(err)
			}
			active := doc.Find(".nav-item.active").First().Text()
			active = strings.TrimSpace(active)
			assert.Equal(t, test.Link, active)
		}
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:27,代碼來源:static_page_test.go

示例2: TestSessionNew

func TestSessionNew(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	It("should return 200", func() {
		record.Get("/login").Expect(200).Expect("Go Wires | Login")
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:7,代碼來源:session_test.go

示例3: TestCheckAuth

func TestCheckAuth(t *testing.T) {
	record := request.TestServer{t, app}

	Describe("when the user is not logged in", func() {
		It("should redirect to the login page", func() {
			ctx := record.Get("/").Expect(302)
			assert.Equal(t, "/login", ctx.ResponseRecorder.Header().Get("Location"))
		})
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:10,代碼來源:check_auth_test.go

示例4: TestNotFound

// Middleware integration test.
func TestNotFound(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	It("should return 404", func() {
		record.Get("/invalidpath").Expect(404)
	})

	It("should return the not found page", func() {
		record.Get("/invalidpath").Expect("here be a 404")
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:12,代碼來源:static_page_test.go

示例5: TestHome

func TestHome(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	It("should return 200", func() {
		record.Get("/").Expect(200)
	})

	It("should return the home page", func() {
		record.Get("/").Expect("App | Home")
		record.Get("/").Expect("home page")
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:12,代碼來源:static_page_test.go

示例6: TestContact

func TestContact(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	It("should return 200", func() {
		record.Get("/contact").Expect(200)
	})

	It("should return the contact page", func() {
		record.Get("/contact").Expect("App | Contact")
		record.Get("/contact").Expect("contact page")
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:12,代碼來源:static_page_test.go

示例7: TestAbout

func TestAbout(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	It("should return 200", func() {
		record.Get("/about").Expect(200)
	})

	It("should return the about page", func() {
		record.Get("/about").Expect("App | About")
		record.Get("/about").Expect("about page")
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:12,代碼來源:static_page_test.go

示例8: TestUserNew

func TestUserNew(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	It("should return 200", func() {
		record.Get("/signup").Expect(200)
	})

	It("should return the signup page", func() {
		record.Get("/signup").Expect("User | Signup")
		record.Get("/signup").Expect(`type="password"`)
	})

	It("should highlight the signup link", func() {
		ctx := record.Get("/signup")
		reader := strings.NewReader(ctx.ResponseRecorder.Body.String())
		doc, err := goquery.NewDocumentFromReader(reader)
		if err != nil {
			t.Fatal(err)
		}
		active := doc.Find(".nav-item.active").First().Text()
		active = strings.TrimSpace(active)
		assert.Equal(t, "Signup", active)
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:24,代碼來源:user_test.go

示例9: TestUserShow

func TestUserShow(t *testing.T) {
	record := request.TestServer{t, TestHandler}

	Describe("when fetching a user that exists", func() {
		BeforeEach(func() {
			user := &models.User{Name: "jason", Email: "[email protected]"}
			if _, err := models.DB.Create(user); err != nil {
				t.Error(err)
			}
		})

		AfterEach(func() {
			clearTable := "TRUNCATE TABLE users; ALTER SEQUENCE users_id_seq RESTART WITH 1"
			if _, err := models.DB.Exec(clearTable); err != nil {
				t.Error(err)
			}
		})

		It("should return 200", func() {
			record.Get("/user/1").Expect(200)
		})

		It("should return the user's profile page", func() {
			record.Get("/user/1").Expect("jason")
			record.Get("/user/1").Expect("[email protected]")
			record.Get("/user/1").Expect("Profile")
		})

		It("should clear the flash cookie", func() {
			// Make an http.ResponseWriter and *http.Request.
			w := httptest.NewRecorder()
			r, err := http.NewRequest("GET", "/", nil)
			if err != nil {
				t.Error(err)
			}

			// Make a flash cookie.
			session, err := models.Store.Get(r, models.FlashName)
			if err != nil {
				t.Error(err)
			}
			session.AddFlash("this is a flash")
			session.Save(r, w)

			// Do a GET with the flash cookie.
			header := w.Header()
			header["Cookie"] = header["Set-Cookie"]
			header.Del("Set-Cookie")
			ctx := record.GetWithHeaders("/user/1", header).Expect("this is a flash")

			// Assert that the response has a Set-Cookie header, meaning that the
			// flash value was changed.
			assert.NotEmpty(t, ctx.ResponseRecorder.Header().Get("Set-Cookie"))
		})
	})

	Describe("when fetching a user that doesn't exist", func() {
		It("should return the not found page", func() {
			record.Get("/user/9000").Expect(404)
			record.Get("/user/9000").Expect("here be a 404")
		})
	})
}
開發者ID:nucleardump,項目名稱:go-wires,代碼行數:63,代碼來源:user_test.go


注:本文中的github.com/nucleartide/request.TestServer.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。