当前位置: 首页>>代码示例>>Golang>>正文


Golang is.NoErr函数代码示例

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


在下文中一共展示了NoErr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestIDofIDSlice

func TestIDofIDSlice(t *testing.T) {
	is := is.New(t)
	var b, s []byte
	for i := 0; i < 64; i++ {
		b = append(b, 0xFF)
		s = append(s, 0x00)
	}
	bigBig := big.NewInt(0)
	bigSmall := big.NewInt(0)
	bigBig = bigBig.SetBytes(b)
	bigSmall = bigSmall.SetBytes(s)
	bigID := asset.ID(*bigBig)
	smallID := asset.ID(*bigSmall)

	encoder := asset.NewIDEncoder()
	is.OK(encoder)
	_, err := io.Copy(encoder, strings.NewReader(`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111c467RPWkcUr5dga8jgywjSup7CMoA9FNqkNjEFgAkEpF9vNktFnx77e2Js11EDL3BNu9MaKFUbacZRt1HYym4b8RNp`))
	is.NoErr(err)
	id := encoder.ID()

	var idSlice asset.IDSlice
	idSlice.Push(&bigID)
	idSlice.Push(&smallID)
	sliceID, err := idSlice.ID()
	is.NoErr(err)

	is.Equal(sliceID.String(), id.String())
}
开发者ID:etcenter,项目名称:c4,代码行数:28,代码来源:slice_test.go

示例2: TestNewWriter_1Sample

func TestNewWriter_1Sample(t *testing.T) {
	t.Parallel()
	is := is.New(t)
	f, err := ioutil.TempFile("", "wavPkgtest")
	is.NoErr(err)
	wr, err := wf.NewWriter(f)
	is.NoErr(err)

	err = wr.WriteSample([]byte{1, 1})
	is.NoErr(err)

	is.Nil(wr.Close())

	f, err = os.Open(f.Name())
	is.NoErr(err)

	b, err := ioutil.ReadAll(f)
	is.NoErr(err)
	is.Equal(len(b), 46)

	is.True(bytes.Contains(b, riff))
	is.True(bytes.Contains(b, wave))
	is.True(bytes.Contains(b, fmt20))

	is.Nil(os.Remove(f.Name()))
}
开发者ID:rtucker88,项目名称:wav,代码行数:26,代码来源:writer_test.go

示例3: TestReadSample

func TestReadSample(t *testing.T) {
	t.Parallel()
	is := is.New(t)
	wavFile := bytes.NewReader(wavWithOneSample)
	wavReader, err := NewReader(wavFile, int64(len(wavWithOneSample)))
	is.NoErr(err)
	is.Equal(uint32(1), wavReader.GetSampleCount())
	sample, err := wavReader.ReadSample()
	is.NoErr(err)
	is.Equal(257, sample)
}
开发者ID:rtucker88,项目名称:wav,代码行数:11,代码来源:reader_test.go

示例4: TestLineComments

func TestLineComments(t *testing.T) {
	is := is.New(t)
	l, err := parse.ParseLine(0, []byte(`* Key: "Value" // comments should be ignored`))
	is.NoErr(err)
	detail := l.Detail()
	is.OK(detail)
	is.Equal(detail.Key, "Key")
	is.Equal(detail.Value.Data, "Value")
	l, err = parse.ParseLine(0, []byte(`* Key: "Value" // comments should be ignored`))
	is.NoErr(err)
	is.Equal(string(l.Bytes), `* Key: "Value"`)
}
开发者ID:lucmichalski,项目名称:silk,代码行数:12,代码来源:line_test.go

示例5: TestParseCostRange

func TestParseCostRange(t *testing.T) {
	is := is.New(t)
	var l meander.CostRange
	var err error
	l, err = meander.ParseCostRange("$$...$$$")
	is.NoErr(err)
	is.Equal(l.From, meander.Cost2)
	is.Equal(l.To, meander.Cost3)
	l, err = meander.ParseCostRange("$...$$$$$")
	is.NoErr(err)
	is.Equal(l.From, meander.Cost1)
	is.Equal(l.To, meander.Cost5)
}
开发者ID:yanai-masahiro,项目名称:goblueprints,代码行数:13,代码来源:cost_level_test.go

示例6: TestIDSliceString

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

	var ids asset.IDSlice
	id1, err := asset.Identify(strings.NewReader("foo"))
	is.NoErr(err)
	id2, err := asset.Identify(strings.NewReader("bar"))
	is.NoErr(err)

	ids.Push(id1)
	ids.Push(id2)

	is.Equal(ids.String(), id1.String()+id2.String())
}
开发者ID:etcenter,项目名称:c4,代码行数:14,代码来源:slice_test.go

示例7: 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

示例8: TestAfter

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

	options := &respond.Options{}
	var aftercall map[string]interface{}
	options.After = func(w http.ResponseWriter, r *http.Request, status int, data interface{}) {
		aftercall = map[string]interface{}{
			"w": w, "r": r, "status": status, "data": data,
		}
	}

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

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

	handler.ServeHTTP(w, r)

	is.OK(aftercall)
	is.Equal(aftercall["w"], w)
	is.Equal(aftercall["r"], r)
	is.Equal(aftercall["status"], testHandler.status)
	is.Equal(aftercall["data"], testHandler.data)

	is.Equal(http.StatusOK, w.Code)
	var data map[string]interface{}
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &data))
	is.Equal(data, testdata)
	is.Equal(w.HeaderMap.Get("Content-Type"), "application/json; charset=utf-8")

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

示例9: 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

示例10: 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]",
			"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

示例11: 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

示例12: 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

示例13: TestParser

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

	groups, err := parse.ParseFile("../testfiles/success/comments.silk.md", "../testfiles/success/comments2.silk.md")
	is.NoErr(err)

	is.Equal(len(groups), 3)
	is.Equal(groups[0].Filename, "../testfiles/success/comments.silk.md")
	is.Equal(groups[1].Filename, "../testfiles/success/comments.silk.md")
	is.Equal(groups[2].Filename, "../testfiles/success/comments2.silk.md")
	is.Equal(groups[0].Title, "Comments and things")
	is.Equal(groups[1].Title, "Another group")

	group := groups[0]
	is.Equal(len(group.Requests), 2)
	is.Equal(len(group.Details), 1)
	is.Equal(group.Details[0].Detail().Key, "Root")
	is.Equal(group.Details[0].Detail().Value.Data, "http://localhost:8080/")

	req1 := group.Requests[0]
	is.Equal("POST", string(req1.Method))
	is.Equal("/comments", string(req1.Path))
	is.Equal(len(req1.Details), 1)
	is.Equal(req1.Details[0].Detail().Key, "Content-Type")
	is.Equal(req1.Details[0].Detail().Value.Data, "application/json")
	is.Equal(req1.ExpectedDetails[0].Detail().Key, "Status")
	is.Equal(req1.ExpectedDetails[0].Detail().Value.Data, 201)
	is.Equal(req1.Body.String(), `{
  "name":    "Mat",
  "comment": "Good work"
}`)
	is.Equal(req1.BodyType, "json")
	is.Equal(req1.ExpectedBody.String(), `{
  "id":      "123",
  "name":    "Mat",
  "comment": "Good work"
}`)
	is.Equal(req1.ExpectedBodyType, "json")

	req2 := group.Requests[1]
	is.Equal("GET", req2.Method)
	is.Equal("/comments/{id}", req2.Path)
	is.Equal(len(req2.Params), 1)
	is.Equal(req2.Params[0].Detail().Key, "pretty")
	is.Equal(req2.Params[0].Detail().Value.Data, true)
	is.Equal(req2.ExpectedDetails[0].Detail().Key, "Status")
	is.Equal(req2.ExpectedDetails[0].Detail().Value.Data, 200)
	is.Equal(req2.ExpectedDetails[1].Detail().Key, "Content-Type")
	is.Equal(req2.ExpectedDetails[1].Detail().Value.Data, "application/json")
	is.Equal(req2.ExpectedBody.String(), `{
  "id":      "123",
  "name":    "Mat",
  "comment": "Good work"
}`)
	is.Equal(req2.ExpectedBody.Number(), 46)

	group = groups[1]
	is.Equal(len(group.Requests), 1)

}
开发者ID:Cedric-Venet,项目名称:silk,代码行数:60,代码来源:parser_test.go

示例14: TestJobWithJobApplicationError

func TestJobWithJobApplicationError(t *testing.T) {
	var jobContext = &ApplicationContext{}
	is := is.New(t)
	w := httptest.NewRecorder()
	requestBody := `{}`
	r := getRequest(jobContext, requestBody)

	next := func(jobApplication *JobApplication) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
	}

	WithJobApplication{next}.ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusBadRequest)
	var body map[string]string
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(len(body), 7)
	is.Equal(body["Message"], "non zero value required")
	is.Equal(body["Milestones"], "non zero value required")
	is.Equal(body["Samples"], "non zero value required")
	is.Equal(body["DeliveryEstimate"], "non zero value required")
	is.Equal(body["FreelancerID"], "non zero value required")
	is.Equal(body["Hours"], "non zero value required")
	is.Equal(body["HourPrice"], "non zero value required")
}
开发者ID:fairlance,项目名称:backend,代码行数:25,代码来源:job_test.go

示例15: TestJobGetJobByID

func TestJobGetJobByID(t *testing.T) {
	jobRepositoryMock := JobRepositoryMock{}
	jobRepositoryMock.GetJobCall.Returns.Job = Job{
		Model: Model{
			ID: 123456789,
		},
		Name:     "Name1",
		Summary:  "Summary1",
		Details:  "Details1",
		ClientID: 1,
		IsActive: true,
		Price:    100,
	}
	var jobContext = &ApplicationContext{
		JobRepository: &jobRepositoryMock,
	}
	is := is.New(t)
	w := httptest.NewRecorder()
	r := getRequest(jobContext, "")

	GetJobByID(0).ServeHTTP(w, r)

	is.Equal(w.Code, http.StatusOK)
	var body Job
	is.NoErr(json.Unmarshal(w.Body.Bytes(), &body))
	is.Equal(body.Model.ID, uint(123456789))
	is.Equal(body.Name, "Name1")
	is.Equal(body.Summary, "Summary1")
	is.Equal(body.Details, "Details1")
	is.Equal(body.IsActive, true)
	is.Equal(body.Price, 100)
}
开发者ID:fairlance,项目名称:backend,代码行数:32,代码来源:job_test.go


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