• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang is.Equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cheekybits/is.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TestFileList

func TestFileList(t *testing.T) {
	is := is.New(t)
	s := NewShell(shellUrl)

	list, err := s.FileList(fmt.Sprintf("/ipfs/%s", examplesHash))
	is.Nil(err)

	is.Equal(list.Type, "Directory")
	is.Equal(list.Size, 0)
	is.Equal(len(list.Links), 6)

	// TODO: document difference in sice betwen 'ipfs ls' and 'ipfs file ls -v'. additional object encoding in data block?
	expected := map[string]UnixLsLink{
		"about":          {Type: "File", Hash: "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V", Name: "about", Size: 1677},
		"contact":        {Type: "File", Hash: "QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y", Name: "contact", Size: 189},
		"help":           {Type: "File", Hash: "QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7", Name: "help", Size: 311},
		"quick-start":    {Type: "File", Hash: "QmUzLxaXnM8RYCPEqLDX5foToi5aNZHqfYr285w2BKhkft", Name: "quick-start", Size: 1686},
		"readme":         {Type: "File", Hash: "QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB", Name: "readme", Size: 1091},
		"security-notes": {Type: "File", Hash: "QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ", Name: "security-notes", Size: 1016},
	}
	for _, l := range list.Links {
		el, ok := expected[l.Name]
		is.True(ok)
		is.NotNil(el)
		is.Equal(*l, el)
	}
}
开发者ID:Patagonicus,项目名称:go-ipfs-api,代码行数:27,代码来源:shell_test.go


示例17: TestUpdateClientByID

func TestUpdateClientByID(t *testing.T) {
	is := is.New(t)
	clientRepositoryMock := &ClientRepositoryMock{}
	clientRepositoryMock.GetClientCall.Returns.Client = &Client{
		User: User{
			Model: Model{
				ID: 1,
			},
		},
	}
	userContext := &ApplicationContext{
		ClientRepository: clientRepositoryMock,
	}

	r := getRequest(userContext, `
    {
        "timezone": "UTC",
        "payment": "paypal",
        "industry": "feet cartoon drawings"
    }`)
	w := httptest.NewRecorder()

	UpdateClientByID(1).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(clientRepositoryMock.GetClientCall.Receives.ID, 1)
	is.Equal(clientRepositoryMock.UpdateClientCall.Receives.Client.Timezone, "UTC")
	is.Equal(clientRepositoryMock.UpdateClientCall.Receives.Client.Payment, "paypal")
	is.Equal(clientRepositoryMock.UpdateClientCall.Receives.Client.Industry, "feet cartoon drawings")
}
开发者ID:fairlance,项目名称:backend,代码行数:30,代码来源:client_test.go


示例18: TestEncoder

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

	options := &respond.Options{}
	var encodercall map[string]interface{}
	options.Encoder = func(w http.ResponseWriter, r *http.Request) respond.Encoder {
		encodercall = map[string]interface{}{
			"w": w, "r": r,
		}
		return &testEncoder{}
	}

	testHandler := &testHandler{
		status: http.StatusOK, data: testdata,
	}
	handler := options.Handler(testHandler)

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

	handler.ServeHTTP(w, r)

	is.OK(encodercall)
	is.Equal(encodercall["w"], w)
	is.Equal(encodercall["r"], r)

	is.Equal(http.StatusOK, w.Code)
	is.Equal(w.Body.String(), "testEncoder")
	is.Equal(w.HeaderMap.Get("Content-Type"), "test/encoder")

}
开发者ID:nkovacs,项目名称:respond,代码行数:31,代码来源:respond_test.go


示例19: TestPlaceJSON

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

	var e meander.Place

	j := `{
   "geometry" : {
      "location" : {
         "lat" : -33.870775,
         "lng" : 151.199025
      }
   },
   "icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/travel_agent-71.png",
   "id" : "21a0b251c9b8392186142c798263e289fe45b4aa",
   "name" : "Rhythmboat Cruises"
  }`

	is.NoErr(json.NewDecoder(strings.NewReader(j)).Decode(&e))

	is.Equal("Rhythmboat Cruises", e.Name)
	is.Equal("http://maps.gstatic.com/mapfiles/place_api/icons/travel_agent-71.png", e.Icon)
	is.Equal(-33.870775, e.Lat)
	is.Equal(151.199025, e.Lng)

}
开发者ID:0-T-0,项目名称:goblueprints,代码行数:25,代码来源:place_test.go


示例20: TestAddClient

func TestAddClient(t *testing.T) {
	is := is.New(t)
	clientRepositoryMock := &ClientRepositoryMock{}
	userContext := &ApplicationContext{
		ClientRepository: clientRepositoryMock,
	}

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

	user := &User{
		Model: Model{
			ID: 1,
		},
	}

	AddClient(user).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	is.Equal(clientRepositoryMock.AddClientCall.Receives.Client.User.ID, 1)
	var body map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	userMap := body["user"].(map[string]interface{})
	is.Equal(userMap["id"], 1)
	is.Equal(body["type"], "client")
}
开发者ID:fairlance,项目名称:backend,代码行数:26,代码来源:client_test.go



注:本文中的github.com/cheekybits/is.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang is.New函数代码示例发布时间:2022-05-23
下一篇:
Golang core.LogMessage类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap