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


Golang assert.Equal函數代碼示例

本文整理匯總了Golang中github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/stretchr/testify/assert.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: TestMarshal

func TestMarshal(t *testing.T) {
	SetDefault("port", 1313)
	Set("name", "Steve")

	type config struct {
		Port int
		Name string
	}

	var C config

	err := Marshal(&C)
	if err != nil {
		t.Fatalf("unable to decode into struct, %v", err)
	}

	assert.Equal(t, &C, &config{Name: "Steve", Port: 1313})

	Set("port", 1234)
	err = Marshal(&C)
	if err != nil {
		t.Fatalf("unable to decode into struct, %v", err)
	}
	assert.Equal(t, &C, &config{Name: "Steve", Port: 1234})
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:25,代碼來源:viper_test.go

示例2: TestRemoveSetting

func TestRemoveSetting(t *testing.T) {
	r := createRouter()

	// It should return 400 if the id is invalid
	req := testRequest(r, "DELETE", "/account/settings/cake", nil)
	req.Header.Set("Authorization", "token")
	assert.Equal(t, 400, req.send().Code)

	// It should return 404 when the setting does not exist
	req.URL.Path = "/account/settings/1881"
	assert.Equal(t, 404, req.send().Code)

	// It should return 200 when removing a setting
	req.URL.Path = "/account/settings/1"
	assert.Equal(t, 200, req.send().Code)

	// It should have removed the setting
	req.Method = "GET"
	req.URL.Path = "/account/settings"
	res := req.send()
	assert.Equal(t, 200, res.Code)
	settings := []Setting{}
	err := json.Unmarshal(res.Body.Bytes(), &settings)
	assert.Nil(t, err)

	for _, setting := range settings {
		if setting.ID == 1 {
			t.Error("Setting with ID 1 did not get removed")
		}
	}
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:31,代碼來源:account_test.go

示例3: TestGzip

func TestGzip(t *testing.T) {
	req, _ := http.NewRequest(echo.GET, "/", nil)
	rec := httptest.NewRecorder()
	c := echo.NewContext(req, echo.NewResponse(rec), echo.New())
	h := func(c *echo.Context) error {
		return c.String(http.StatusOK, "test")
	}

	// Skip if no Accept-Encoding header
	Gzip()(h)(c)
	assert.Equal(t, http.StatusOK, rec.Code)
	assert.Equal(t, "test", rec.Body.String())

	// Gzip
	req, _ = http.NewRequest(echo.GET, "/", nil)
	req.Header.Set(echo.AcceptEncoding, "gzip")
	rec = httptest.NewRecorder()
	c = echo.NewContext(req, echo.NewResponse(rec), echo.New())
	Gzip()(h)(c)
	assert.Equal(t, http.StatusOK, rec.Code)
	assert.Equal(t, "gzip", rec.Header().Get(echo.ContentEncoding))
	r, err := gzip.NewReader(rec.Body)
	defer r.Close()
	if assert.NoError(t, err) {
		buf := new(bytes.Buffer)
		buf.ReadFrom(r)
		assert.Equal(t, "test", buf.String())
	}
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:29,代碼來源:compress_test.go

示例4: TestGetEpisodes

func TestGetEpisodes(t *testing.T) {
	r := createRouter()

	expectedJSON := testJSON([]Episode{
		Episode{
			ID:     1,
			CastID: 1,
		},
	})

	// It should return 200 and a list of episodes
	req := testRequest(r, "GET", "/library/episodes/1", nil)
	req.Header.Set("Authorization", "token")
	res := req.send()
	assert.Equal(t, 200, res.Code)
	assert.Equal(t, expectedJSON, res.Body.String())

	// It should return 200 and an empty list if the cast is not found
	req.URL.Path = "/library/episodes/1337"
	res = req.send()
	assert.Equal(t, 200, res.Code)
	assert.Equal(t, testJSON([]Episode{}), res.Body.String())

	// It should return 400 if the ID is invalid
	req.URL.Path = "/library/episodes/datcast"
	assert.Equal(t, 400, req.send().Code)
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:27,代碼來源:episodes_test.go

示例5: TestRouterMultiRoute

func TestRouterMultiRoute(t *testing.T) {
	e := New()
	r := e.router

	// Routes
	r.Add(GET, "/users", func(c *Context) error {
		c.Set("path", "/users")
		return nil
	}, e)
	r.Add(GET, "/users/:id", func(c *Context) error {
		return nil
	}, e)
	c := NewContext(nil, nil, e)

	// Route > /users
	h, _ := r.Find(GET, "/users", c)
	if assert.NotNil(t, h) {
		h(c)
		assert.Equal(t, "/users", c.Get("path"))
	}

	// Route > /users/:id
	h, _ = r.Find(GET, "/users/1", c)
	if assert.NotNil(t, h) {
		assert.Equal(t, "1", c.P(0))
	}

	// Route > /user
	h, _ = r.Find(GET, "/user", c)
	assert.Nil(t, h)
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:31,代碼來源:router_test.go

示例6: TestAddEvents

func TestAddEvents(t *testing.T) {
	r := createRouter()

	// It should return 400 if json is not set
	req := testRequest(r, "POST", "/library/events", nil)
	req.Header.Set("Authorization", "evtest1")
	assert.Equal(t, 400, req.send().Code)

	// It should return 400 if the json is bad
	req.PostForm = url.Values{}
	req.PostForm.Set("json", "real_bad_json")
	assert.Equal(t, 400, req.send().Code)

	// It should return 200 when proper json is sent
	req.PostForm.Set("json", testJSON([]Event{
		Event{
			Type:              30,
			EpisodeID:         10,
			PositionTS:        481,
			ClientTS:          11,
			ConcurrentOrder:   0,
			ClientName:        "Castcloud",
			ClientDescription: "oink",
		},
	}))
	assert.Equal(t, 200, req.send().Code)

	// There should now be 2 events
	req.Method = "GET"
	res := checkEvents(t, req)
	assert.Len(t, res.Events, 2)
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:32,代碼來源:events_test.go

示例7: TestStoreGetCasts

func TestStoreGetCasts(t *testing.T) {
	casts := store.GetCasts()
	assert.NotNil(t, casts)
	assert.True(t, len(casts) > 0)
	assert.Equal(t, uint64(1), casts[0].ID)
	assert.Equal(t, "test.go", casts[0].URL)
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:7,代碼來源:store_bolt_casts_test.go

示例8: TestEchoHandler

func TestEchoHandler(t *testing.T) {
	e := New()

	// HandlerFunc
	e.Get("/1", HandlerFunc(func(c *Context) error {
		return c.String(http.StatusOK, "1")
	}))

	// func(*echo.Context) error
	e.Get("/2", func(c *Context) error {
		return c.String(http.StatusOK, "2")
	})

	// http.Handler/http.HandlerFunc
	e.Get("/3", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("3"))
	}))

	// func(http.ResponseWriter, *http.Request)
	e.Get("/4", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("4"))
	})

	for _, p := range []string{"1", "2", "3", "4"} {
		c, b := request(GET, "/"+p, e)
		assert.Equal(t, http.StatusOK, c)
		assert.Equal(t, p, b)
	}

	// Unknown
	assert.Panics(t, func() {
		e.Get("/5", nil)
	})
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:34,代碼來源:echo_test.go

示例9: TestAliasInConfigFile

func TestAliasInConfigFile(t *testing.T) {
	// the config file specifies "beard".  If we make this an alias for
	// "hasbeard", we still want the old config file to work with beard.
	RegisterAlias("beard", "hasbeard")
	assert.Equal(t, true, Get("hasbeard"))
	Set("hasbeard", false)
	assert.Equal(t, false, Get("beard"))
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:8,代碼來源:viper_test.go

示例10: TestRedirectToSlash

func TestRedirectToSlash(t *testing.T) {
	req, _ := http.NewRequest(echo.GET, "/users", nil)
	rec := httptest.NewRecorder()
	c := echo.NewContext(req, echo.NewResponse(rec), echo.New())
	RedirectToSlash(RedirectToSlashOptions{Code: http.StatusTemporaryRedirect})(c)
	assert.Equal(t, http.StatusTemporaryRedirect, rec.Code)
	assert.Equal(t, "/users/", c.Response().Header().Get("Location"))
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:8,代碼來源:slash_test.go

示例11: TestLevels

func TestLevels(t *testing.T) {
	SetStdoutThreshold(LevelError)
	assert.Equal(t, StdoutThreshold(), LevelError)
	SetLogThreshold(LevelCritical)
	assert.Equal(t, LogThreshold(), LevelCritical)
	assert.NotEqual(t, StdoutThreshold(), LevelCritical)
	SetStdoutThreshold(LevelWarn)
	assert.Equal(t, StdoutThreshold(), LevelWarn)
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:9,代碼來源:jww_test.go

示例12: TestGetSettings

func TestGetSettings(t *testing.T) {
	r := createRouter()

	// It should return 200 and a list of settings
	req := testRequest(r, "GET", "/account/settings", nil)
	req.Header.Set("Authorization", "token")
	res := req.send()
	assert.Equal(t, 200, res.Code)
	assert.Equal(t, testJSON([]Setting{}), res.Body.String())
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:10,代碼來源:account_test.go

示例13: TestJWTAuth

func TestJWTAuth(t *testing.T) {
	req, _ := http.NewRequest(echo.GET, "/", nil)
	rec := httptest.NewRecorder()
	c := echo.NewContext(req, echo.NewResponse(rec), echo.New())
	key := []byte("key")
	fn := func(kid string, method jwt.SigningMethod) ([]byte, error) {
		return key, nil
	}
	ja := JWTAuth(fn)
	token := jwt.New(jwt.SigningMethodHS256)
	token.Claims["foo"] = "bar"
	token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
	ts, err := token.SignedString(key)
	assert.NoError(t, err)

	// Valid credentials
	auth := Bearer + " " + ts
	req.Header.Set(echo.Authorization, auth)
	assert.NoError(t, ja(c))

	//---------------------
	// Invalid credentials
	//---------------------

	// Expired token
	token.Claims["exp"] = time.Now().Add(-time.Second).Unix()
	ts, err = token.SignedString(key)
	assert.NoError(t, err)
	auth = Bearer + " " + ts
	req.Header.Set(echo.Authorization, auth)
	he := ja(c).(*echo.HTTPError)
	assert.Equal(t, http.StatusUnauthorized, he.Code())

	// Empty Authorization header
	req.Header.Set(echo.Authorization, "")
	he = ja(c).(*echo.HTTPError)
	assert.Equal(t, http.StatusBadRequest, he.Code())

	// Invalid Authorization header
	auth = "token"
	req.Header.Set(echo.Authorization, auth)
	he = ja(c).(*echo.HTTPError)
	assert.Equal(t, http.StatusBadRequest, he.Code())

	// Invalid scheme
	auth = "Bear token"
	req.Header.Set(echo.Authorization, auth)
	he = ja(c).(*echo.HTTPError)
	assert.Equal(t, http.StatusBadRequest, he.Code())

	// WebSocket
	c.Request().Header.Set(echo.Upgrade, echo.WebSocket)
	assert.NoError(t, ja(c))
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:54,代碼來源:auth_test.go

示例14: TestEchoGroup

func TestEchoGroup(t *testing.T) {
	e := New()
	buf := new(bytes.Buffer)
	e.Use(func(*Context) error {
		buf.WriteString("0")
		return nil
	})
	h := func(*Context) error { return nil }

	//--------
	// Routes
	//--------

	e.Get("/users", h)

	// Group
	g1 := e.Group("/group1")
	g1.Use(func(*Context) error {
		buf.WriteString("1")
		return nil
	})
	g1.Get("/", h)

	// Group with no parent middleware
	g2 := e.Group("/group2", func(*Context) error {
		buf.WriteString("2")
		return nil
	})
	g2.Get("/", h)

	// Nested groups
	g3 := e.Group("/group3")
	g4 := g3.Group("/group4")
	g4.Get("/", func(c *Context) error {
		return c.NoContent(http.StatusOK)
	})

	request(GET, "/users", e)
	// println(len(e.middleware))
	assert.Equal(t, "0", buf.String())

	buf.Reset()
	request(GET, "/group1/", e)
	// println(len(g1.echo.middleware))
	assert.Equal(t, "01", buf.String())

	buf.Reset()
	request(GET, "/group2/", e)
	assert.Equal(t, "2", buf.String())

	buf.Reset()
	c, _ := request(GET, "/group3/group4/", e)
	assert.Equal(t, http.StatusOK, c)
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:54,代碼來源:echo_test.go

示例15: TestMarshalling

func TestMarshalling(t *testing.T) {
	SetConfigType("yaml")
	r := bytes.NewReader(yamlExample)

	marshalReader(r, v.config)
	assert.True(t, InConfig("name"))
	assert.False(t, InConfig("state"))
	assert.Equal(t, "steve", Get("name"))
	assert.Equal(t, []interface{}{"skateboarding", "snowboarding", "go"}, Get("hobbies"))
	assert.Equal(t, map[interface{}]interface{}{"jacket": "leather", "trousers": "denim"}, Get("clothing"))
	assert.Equal(t, 35, Get("age"))
}
開發者ID:Castcloud,項目名稱:castcloud-go-server,代碼行數:12,代碼來源:viper_test.go


注:本文中的github.com/Castcloud/castcloud-go-server/Godeps/_workspace/src/github.com/stretchr/testify/assert.Equal函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。