當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。