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


Golang is.Equal函數代碼示例

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


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

示例1: TestLogin

func TestLogin(t *testing.T) {
	is := is.New(t)
	userRepositoryMock := &UserRepositoryMock{}
	userRepositoryMock.CheckCredentialsCall.Returns.UserType = "freelancer"
	userRepositoryMock.CheckCredentialsCall.Returns.User = User{
		Model: Model{
			ID: 1,
		},
		FirstName: "firstname",
		LastName:  "lastname",
		Password:  "password",
		Email:     "[email protected]",
	}
	userContext := &ApplicationContext{
		UserRepository: userRepositoryMock,
	}

	r := getRequest(userContext, `
		{
			"email": "[email protected].com",
			"password": "notimportant"
		}
	`)
	w := httptest.NewRecorder()

	Login(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body["id"], 1)
	is.OK(body["token"])
	is.Equal(body["type"], "freelancer")
}
開發者ID:fairlance,項目名稱:backend,代碼行數:34,代碼來源:login_test.go

示例2: TestAddFreelancerReferenceByID

func TestAddFreelancerReferenceByID(t *testing.T) {
	is := is.New(t)
	referenceRepositoryMock := &ReferenceRepositoryMock{}
	var freelancerContext = &ApplicationContext{
		ReferenceRepository: referenceRepositoryMock,
	}

	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, ``)

	reference := Reference{
		Title:   "title",
		Content: "content",
		Media: Media{
			Image: "image",
			Video: "video",
		},
	}

	addFreelancerReferenceByID{3, &reference}.ServeHTTP(w, r)
	receivedReference := referenceRepositoryMock.AddReferenceCall.Receives.Reference

	is.Equal(receivedReference.Title, "title")
	is.Equal(receivedReference.Content, "content")
	is.Equal(receivedReference.Media.Image, "image")
	is.Equal(receivedReference.Media.Video, "video")
	is.Equal(referenceRepositoryMock.AddReferenceCall.Receives.ID, 3)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:28,代碼來源:freelancer_test.go

示例3: TestAddFreelancer

func TestAddFreelancer(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	freelancerContext := &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}

	r := getRequest(freelancerContext, ``)
	w := httptest.NewRecorder()

	user := &User{
		Model: Model{
			ID: 1,
		},
		FirstName: "first",
		LastName:  "last",
		Email:     "[email protected]",
	}

	AddFreelancer(user).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.Model.ID, 1)
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.FirstName, "first")
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.LastName, "last")
	is.Equal(freelancerRepositoryMock.AddFreelancerCall.Receives.Freelancer.User.Email, "[email protected]")
}
開發者ID:fairlance,項目名稱:backend,代碼行數:27,代碼來源:freelancer_test.go

示例4: TestIndexFreelancer

func TestIndexFreelancer(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	freelancerRepositoryMock.GetAllFreelancersCall.Returns.Freelancers = []Freelancer{
		Freelancer{
			User: User{
				Model: Model{
					ID: 1,
				},
			},
		},
		Freelancer{
			User: User{
				Model: Model{
					ID: 2,
				},
			},
		},
	}
	freelancerContext := &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}

	r := getRequest(freelancerContext, ``)
	w := httptest.NewRecorder()

	IndexFreelancer(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body []Freelancer
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body[0].Model.ID, 1)
	is.Equal(body[1].Model.ID, 2)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:34,代碼來源:freelancer_test.go

示例5: TestWithReference

func TestWithReference(t *testing.T) {
	is := is.New(t)
	referenceRepositoryMock := &ReferenceRepositoryMock{}
	var freelancerContext = &ApplicationContext{
		ReferenceRepository: referenceRepositoryMock,
	}

	w := httptest.NewRecorder()
	r := getRequest(freelancerContext, `
	{
		"content":      "content",
		"title":		"title",
		"media":		{
			"image":	"image",
			"video":	"video"
		}
	}`)

	next := func(reference *Reference) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			is.Equal(reference.Title, "title")
			is.Equal(reference.Content, "content")
			is.Equal(reference.Media.Image, "image")
			is.Equal(reference.Media.Video, "video")
		})
	}

	withReference{next}.ServeHTTP(w, r)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:29,代碼來源:freelancer_test.go

示例6: TestGetFreelancerByID

func TestGetFreelancerByID(t *testing.T) {
	is := is.New(t)
	freelancerRepositoryMock := &FreelancerRepositoryMock{}
	freelancerRepositoryMock.GetFreelancerCall.Returns.Freelancer = Freelancer{
		User: User{
			Model: Model{
				ID: 1,
			},
		},
	}
	freelancerContext := &ApplicationContext{
		FreelancerRepository: freelancerRepositoryMock,
	}

	r := getRequest(freelancerContext, ``)
	w := httptest.NewRecorder()

	GetFreelancerByID(1).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(freelancerRepositoryMock.GetFreelancerCall.Receives.ID, 1)
	var body Freelancer
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body.Model.ID, 1)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:25,代碼來源:freelancer_test.go

示例7: TestValueEqual

func TestValueEqual(t *testing.T) {
	is := is.New(t)

	v := ParseValue([]byte("something"))
	is.True(v.Equal("something"))
	is.False(v.Equal("else"))
	is.Equal("string", v.Type())

	v = ParseValue([]byte("123"))
	is.Equal("float64", v.Type())

	v = ParseValue([]byte("/^2.{2}$/"))
	is.True(v.Equal(200))
	is.True(v.Equal(201))
	is.False(v.Equal(404))
	is.Equal("regex", v.Type())

	v = ParseValue([]byte("/application/json/"))
	is.True(v.Equal("application/json"))
	is.True(v.Equal("application/json; charset=utf-8"))
	is.True(v.Equal("text/xml; application/json; charset=utf-8"))
	is.False(v.Equal("text/xml; charset=utf-8"))
	is.Equal("regex", v.Type())

}
開發者ID:lucmichalski,項目名稱:silk,代碼行數:25,代碼來源:value_test.go

示例8: TestJobWithJob

func TestJobWithJob(t *testing.T) {
	var jobContext = &ApplicationContext{}
	is := is.New(t)
	w := httptest.NewRecorder()
	requestBody := `{
		"name": "Name1",
		"details": "Details1",
		"summary": "Summary1",
		"clientId": 1
	}`
	r := getRequest(jobContext, requestBody)

	next := func(job *Job) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			is.Equal(job.Name, "Name1")
			is.Equal(job.Details, "Details1")
			is.Equal(job.Summary, "Summary1")
			is.Equal(job.ClientID, 1)
		})
	}

	WithJob{next}.ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:25,代碼來源:job_test.go

示例9: TestAppendOrder

func TestAppendOrder(t *testing.T) {
	is := is.New(t)
	byteData := [4][]byte{
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0d, 0x24},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0xfa, 0x28},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xac, 0xad, 0x10},
	}
	expectedIDs := [4]string{
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121`,
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111211`,
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111112111`,
		`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111121111`,
	}
	for k := 0; k < 4; k++ {
		b := byteData[k]
		bignum := big.NewInt(0)
		bignum = bignum.SetBytes(b)
		id := asset.ID(*bignum)
		is.Equal(id.String(), expectedIDs[k])

		id2, err := asset.ParseID(expectedIDs[k])
		is.NoErr(err)
		bignum2 := big.Int(*id2)
		b = (&bignum2).Bytes()
		size := len(b)
		for size < 64 {
			b = append([]byte{0}, b...)
			size++
		}
		for i, bb := range b {
			is.Equal(bb, byteData[k][i])
		}
	}
}
開發者ID:etcenter,項目名稱:c4,代碼行數:35,代碼來源:id_test.go

示例10: TestWithUser

func TestWithUser(t *testing.T) {
	is := is.New(t)
	userContext := &ApplicationContext{}
	r := getRequest(userContext, `
		{
            "firstName": "firstname",
            "lastName": "lastname",
			"email": "[email protected]",
			"password": "password"
		}
	`)
	w := httptest.NewRecorder()
	withUser := WithUser{
		next: func(u *User) http.Handler {
			return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				is.Equal(u.FirstName, "firstname")
				is.Equal(u.LastName, "lastname")
				is.Equal(u.Email, "[email protected]")
				is.Equal(u.Password, "password")
			})
		},
	}

	withUser.ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:27,代碼來源:user_test.go

示例11: TestOnceReset

func TestOnceReset(t *testing.T) {
	is := is.New(t)
	var calls int
	var c resync.Once
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	is.Equal(calls, 1)
	c.Reset()
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	c.Do(func() {
		calls++
	})
	is.Equal(calls, 2)
}
開發者ID:odwrtw,項目名稱:resync,代碼行數:26,代碼來源:once_test.go

示例12: TestValueEqual

func TestValueEqual(t *testing.T) {
	is := is.New(t)

	v := ParseValue([]byte("something"))
	is.True(v.Equal("something"))
	is.False(v.Equal("else"))
	is.Equal("string", v.Type())

	v = ParseValue([]byte("123"))
	is.Equal("float64", v.Type())

	v = ParseValue([]byte("/^2.{2}$/"))
	is.True(v.Equal(200))
	is.True(v.Equal(201))
	is.False(v.Equal(404))
	is.Equal("regex", v.Type())

	v = ParseValue([]byte("/application/json/"))
	is.True(v.Equal("application/json"))
	is.True(v.Equal("application/json; charset=utf-8"))
	is.True(v.Equal("text/xml; application/json; charset=utf-8"))
	is.False(v.Equal("text/xml; charset=utf-8"))
	is.Equal("regex", v.Type())
	is.Equal(`/application/json/`, v.String())

	v = ParseValue([]byte("/Silk/"))
	is.True(v.Equal("My name is Silk."))
	is.True(v.Equal("Silk is my name."))
	is.False(v.Equal("I don't contain that word!"))
}
開發者ID:matryer,項目名稱:silk,代碼行數:30,代碼來源:value_test.go

示例13: TestIndexProject

func TestIndexProject(t *testing.T) {
	is := is.New(t)
	projectRepositoryMock := &ProjectRepositoryMock{}
	projectRepositoryMock.GetAllProjectsCall.Returns.Projects = []Project{
		Project{
			Model: Model{
				ID: 1,
			},
		},
		Project{
			Model: Model{
				ID: 2,
			},
		},
	}
	userContext := &ApplicationContext{
		ProjectRepository: projectRepositoryMock,
	}

	r := getRequest(userContext, ``)
	w := httptest.NewRecorder()

	IndexProject(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body []Project
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body[0].Model.ID, 1)
	is.Equal(body[1].Model.ID, 2)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:30,代碼來源:project_test.go

示例14: TestProjectGetByID

func TestProjectGetByID(t *testing.T) {
	projectRepositoryMock := ProjectRepositoryMock{}
	projectRepositoryMock.GetByIDCall.Returns.Project = Project{
		Model: Model{
			ID: 123456789,
		},
		Name:        "Name1",
		Description: "Description1",
		ClientID:    1,
		IsActive:    true,
	}
	var context = &ApplicationContext{
		ProjectRepository: &projectRepositoryMock,
	}
	is := is.New(t)
	w := httptest.NewRecorder()
	r := getRequest(context, "")

	GetProjectByID(0).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body Project
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body.Model.ID, uint(123456789))
	is.Equal(body.Name, "Name1")
	is.Equal(body.Description, "Description1")
	is.Equal(body.IsActive, true)
}
開發者ID:fairlance,項目名稱:backend,代碼行數:28,代碼來源:project_test.go

示例15: TestWithError

func TestWithError(t *testing.T) {
	is := is.New(t)

	w := httptest.NewRecorder()
	r := newTestRequest()

	err := errors.New("something went wrong")

	opts := &respond.Options{
		Before: func(w http.ResponseWriter, r *http.Request, status int, data interface{}) (int, interface{}) {
			if err, ok := data.(error); ok {
				return status, map[string]interface{}{"error": err.Error()}
			}
			return status, data
		},
	}
	testHandler := &testHandler{
		status: http.StatusInternalServerError,
		data:   err,
	}
	handler := opts.Handler(testHandler)

	handler.ServeHTTP(w, r)

	is.Equal(http.StatusInternalServerError, w.Code)
	var data map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &data))
	is.Equal(data, map[string]interface{}{"error": err.Error()})
	is.Equal(w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")
}
開發者ID:nkovacs,項目名稱:respond,代碼行數:30,代碼來源:respond_test.go


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