本文整理匯總了Golang中github.com/ninnemana/API/helpers/apicontextmock.Mock函數的典型用法代碼示例。如果您正苦於以下問題:Golang Mock函數的具體用法?Golang Mock怎麽用?Golang Mock使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Mock函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestAppGuides
func TestAppGuides(t *testing.T) {
MockedDTX := &apicontext.DataContext{}
var err error
if MockedDTX, err = apicontextmock.Mock(); err != nil {
return
}
Convey("Test Create AppGuide", t, func() {
var err error
var ag ApplicationGuide
//create
ag.FileType = "pdf"
ag.Url = "test.com"
ag.Website.ID = MockedDTX.WebsiteID
err = ag.Create(MockedDTX)
So(err, ShouldBeNil)
//get
err = ag.Get(MockedDTX)
So(err, ShouldBeNil)
//get by site
ags, err := ag.GetBySite(MockedDTX)
So(err, ShouldBeNil)
So(len(ags), ShouldBeGreaterThanOrEqualTo, 1)
//delete
err = ag.Delete()
So(err, ShouldBeNil)
})
_ = apicontextmock.DeMock(MockedDTX)
}
示例2: TestBadCrudStmts
func TestBadCrudStmts(t *testing.T) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
Convey("Testing bad statements", t, func() {
var l CustomerLocation
l.Name = "test"
l.Address = "testA"
l.City = "Tes"
l.State.Id = 12
l.IsPrimary = true
createLocation = "Bad Query Stmt"
updateLocation = "Bad Query Stmt"
deleteLocation = "Bad Query Stmt"
Convey("Testing Bad Create()", func() {
err := l.Create(MockedDTX)
So(err, ShouldNotBeNil)
})
Convey("Testing Bad Update()", func() {
l.Name = "test2"
err := l.Update(MockedDTX)
So(err, ShouldNotBeNil)
})
Convey("Testing Bad Delete()", func() {
err := l.Delete(MockedDTX)
So(err, ShouldNotBeNil)
})
})
_ = apicontextmock.DeMock(MockedDTX)
}
示例3: TestGetMakes
func TestGetMakes(t *testing.T) {
var l Lookup
l.Brands = append(l.Brands, 1)
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
Convey("Testing GetMakes() without year", t, func() {
err := l.GetMakes(MockedDTX)
So(err, ShouldEqual, nil)
So(l.Makes, ShouldNotEqual, nil)
So(len(l.Makes), ShouldEqual, 0)
})
Convey("Testing GetMakes() with bogus year", t, func() {
l.Vehicle.Base.Year = 1
err := l.GetMakes(MockedDTX)
So(err, ShouldEqual, nil)
So(l.Makes, ShouldNotEqual, nil)
So(len(l.Makes), ShouldEqual, 0)
So(l.Vehicle.Base.Year, ShouldEqual, 1)
})
Convey("Testing GetMakes() with year", t, func() {
l.Vehicle.Base.Year = 2010
err := l.GetMakes(MockedDTX)
So(err, ShouldEqual, nil)
So(l.Makes, ShouldNotEqual, nil)
So(l.Makes, ShouldHaveSameTypeAs, []string{})
So(l.Vehicle.Base.Year, ShouldEqual, 2010)
})
_ = apicontextmock.DeMock(MockedDTX)
}
示例4: TestVinLookup
func TestVinLookup(t *testing.T) {
dtx, err := apicontextmock.Mock()
if err != nil {
t.Log(err)
}
Convey("Testing VinPartLookup", t, func() {
vs, err := VinPartLookup(buickVin, dtx)
if err != sql.ErrNoRows {
So(err, ShouldBeNil)
So(len(vs.Parts), ShouldBeGreaterThanOrEqualTo, 1)
}
if err != sql.ErrNoRows {
vs, err = VinPartLookup(taurusVin, dtx)
So(err, ShouldBeNil)
So(len(vs.Parts), ShouldBeGreaterThanOrEqualTo, 1)
//Make sure it's a Taurus - VINs should be constant
So(vs.Vehicle.Base.Model, ShouldEqual, "Taurus")
//We have 2010 Taurus Hitches
So(len(vs.Parts), ShouldBeGreaterThanOrEqualTo, 1)
}
})
_ = apicontextmock.DeMock(dtx)
}
示例5: TestCustomerLocations
func TestCustomerLocations(t *testing.T) {
var l CustomerLocation
var err error
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
Convey("Testing Locations", t, func() {
Convey("Testing Create", func() {
l.Name = "test"
l.Address = "testA"
l.City = "Tes"
l.State.Id = 12
l.IsPrimary = true
l.Email = "Tes"
l.Fax = "Tes"
l.Phone = "Tes"
l.Coordinates.Latitude = 44.913687
l.Coordinates.Longitude = -91.89981
l.CustomerId = MockedDTX.CustomerID
l.ContactPerson = "Tes"
l.IsPrimary = true
l.PostalCode = "Tes"
l.ShippingDefault = false
err := l.Create(MockedDTX)
So(err, ShouldBeNil)
})
Convey("Update", func() {
l.Name = "Chuck Norris"
err := l.Update(MockedDTX)
So(err, ShouldBeNil)
So(l.Name, ShouldNotEqual, "test")
})
Convey("Testing GetAll()", func() {
locations, err := GetAllLocations(MockedDTX)
So(len(locations), ShouldBeGreaterThanOrEqualTo, 0)
So(err, ShouldBeNil)
})
Convey("Get", func() {
err = l.Get()
So(err, ShouldBeNil)
So(l, ShouldNotBeNil)
})
Convey("Delete", func() {
err := l.Delete(MockedDTX)
So(err, ShouldBeNil)
})
})
_ = apicontextmock.DeMock(MockedDTX)
}
示例6: TestGetFaqs
func TestGetFaqs(t *testing.T) {
var f Faq
var err error
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
f.Question = "testQuestion"
f.Answer = "testAnswer"
Convey("Testing Create", t, func() {
err = f.Create(MockedDTX)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
So(f.Question, ShouldEqual, "testQuestion")
So(f.Answer, ShouldEqual, "testAnswer")
})
Convey("Testing Update", t, func() {
f.Question = "testQuestion222"
f.Answer = "testAnswer222"
err = f.Update(MockedDTX)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
So(f.Question, ShouldEqual, "testQuestion222")
So(f.Answer, ShouldEqual, "testAnswer222")
})
Convey("Testing Get", t, func() {
err = f.Get(MockedDTX)
So(err, ShouldBeNil)
So(f, ShouldNotBeNil)
So(f.Question, ShouldHaveSameTypeAs, "str")
So(f.Answer, ShouldHaveSameTypeAs, "str")
var fs Faqs
fs, err = GetAll(MockedDTX)
So(fs, ShouldNotBeNil)
So(err, ShouldBeNil)
So(len(fs), ShouldNotBeNil)
as, err := Search(MockedDTX, f.Question, "", "1", "0")
So(as, ShouldNotBeNil)
So(err, ShouldBeNil)
So(as.Pagination.Page, ShouldEqual, 1)
So(as.Pagination.ReturnedCount, ShouldNotBeNil)
So(as.Pagination.PerPage, ShouldNotBeNil)
So(as.Pagination.PerPage, ShouldEqual, len(as.Objects))
})
Convey("Testing Delete", t, func() {
err = f.Delete()
So(err, ShouldBeNil)
})
_ = apicontextmock.DeMock(MockedDTX)
}
示例7: BenchmarkSearch
func BenchmarkSearch(b *testing.B) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
for i := 0; i < b.N; i++ {
Search("Title", "", "", "", "", "", "", "1", "1", MockedDTX)
}
_ = apicontextmock.DeMock(MockedDTX)
}
示例8: BenchmarkGetLeads
func BenchmarkGetLeads(b *testing.B) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
for i := 0; i < b.N; i++ {
GetLeads("1", "1", MockedDTX)
}
_ = apicontextmock.DeMock(MockedDTX)
}
示例9: BenchmarkGetAllTestimonials
func BenchmarkGetAllTestimonials(b *testing.B) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
for i := 0; i < b.N; i++ {
GetAllTestimonials(0, 1, false, MockedDTX)
}
_ = apicontextmock.DeMock(MockedDTX)
}
示例10: BenchmarkGetAllContacts
func BenchmarkGetAllContacts(b *testing.B) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
for i := 0; i < b.N; i++ {
GetAllContacts(1, 1, MockedDTX)
}
_ = apicontextmock.DeMock(MockedDTX)
}
示例11: BenchmarkGetAllTechSupport
func BenchmarkGetAllTechSupport(b *testing.B) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
for i := 0; i < b.N; i++ {
GetAllTechSupport(MockedDTX)
}
_ = apicontextmock.DeMock(MockedDTX)
}
示例12: TestFaqs
func TestFaqs(t *testing.T) {
var f faq_model.Faq
var err error
dtx, err := apicontextmock.Mock()
if err != nil {
t.Log(err)
}
Convey("Test Faqs", t, func() {
//test create
form := url.Values{"question": {"test"}, "answer": {"testAnswer"}}
v := form.Encode()
body := strings.NewReader(v)
testThatHttp.Request("post", "/faqs", "", "", Create, body, "application/x-www-form-urlencoded")
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
So(f, ShouldHaveSameTypeAs, faq_model.Faq{})
//test update
form = url.Values{"question": {"test new"}, "answer": {"testAnswer new"}}
v = form.Encode()
body = strings.NewReader(v)
testThatHttp.RequestWithDtx("put", "/faqs/", ":id", strconv.Itoa(f.ID), Update, body, "application/x-www-form-urlencoded", dtx)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
So(f, ShouldHaveSameTypeAs, faq_model.Faq{})
//test get
testThatHttp.RequestWithDtx("get", "/faqs/", ":id", strconv.Itoa(f.ID), Get, nil, "application/x-www-form-urlencoded", dtx)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
So(f, ShouldHaveSameTypeAs, faq_model.Faq{})
So(f.Question, ShouldEqual, "test new")
//test getall
testThatHttp.Request("get", "/faqs", "", "", GetAll, nil, "application/x-www-form-urlencoded")
So(testThatHttp.Response.Code, ShouldEqual, 200)
var fs faq_model.Faqs
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &fs)
So(len(fs), ShouldBeGreaterThanOrEqualTo, 0)
//test search - responds w/ horrid pagination object
testThatHttp.Request("get", "/faqs/search", "", "?question=test new", Search, nil, "application/x-www-form-urlencoded")
So(testThatHttp.Response.Code, ShouldEqual, 200)
var l pagination.Objects
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &l)
So(len(l.Objects), ShouldBeGreaterThanOrEqualTo, 0)
//test delete
testThatHttp.Request("delete", "/faqs/", ":id", strconv.Itoa(f.ID), Delete, nil, "application/x-www-form-urlencoded")
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &f)
So(f, ShouldHaveSameTypeAs, faq_model.Faq{})
})
_ = apicontextmock.DeMock(dtx)
}
示例13: TestTestimonials
func TestTestimonials(t *testing.T) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
var test Testimonial
test.BrandID = MockedDTX.BrandID
Convey("Testing Create Testimonial", t, func() {
test.Content = "Test Content"
err = test.Create()
So(err, ShouldBeNil)
})
Convey("Update", t, func() {
test.Content = "New Content"
test.Active = true
test.Approved = true
err = test.Update()
So(err, ShouldBeNil)
})
Convey("Get testimonial", t, func() {
err = test.Get(MockedDTX)
So(err, ShouldBeNil)
})
Convey("GetAll - No paging", t, func() {
ts, err := GetAllTestimonials(0, 1, false, MockedDTX)
So(err, ShouldBeNil)
So(len(ts), ShouldBeGreaterThan, 0)
})
Convey("GetAll - Paged", t, func() {
ts, err := GetAllTestimonials(0, 1, false, MockedDTX)
So(err, ShouldBeNil)
So(len(ts), ShouldBeGreaterThan, 0)
})
Convey("GetAll - randomized", t, func() {
ts, err := GetAllTestimonials(0, 1, true, MockedDTX)
So(err, ShouldBeNil)
So(len(ts), ShouldBeGreaterThan, 0)
})
Convey("Delete", t, func() {
err = test.Delete()
So(err, ShouldBeNil)
})
_ = apicontextmock.DeMock(MockedDTX)
}
示例14: BenchmarkGetAllBlogCategories
func BenchmarkGetAllBlogCategories(b *testing.B) {
MockedDTX := &apicontext.DataContext{}
var err error
if MockedDTX, err = apicontextmock.Mock(); err != nil {
return
}
for i := 0; i < b.N; i++ {
GetAllCategories(MockedDTX)
}
_ = apicontextmock.DeMock(MockedDTX)
}
示例15: TestPart
func TestPart(t *testing.T) {
MockedDTX, err := apicontextmock.Mock()
if err != nil {
return
}
Convey("Testing Basics", t, func() {
p := Part{
ID: 11000,
}
err := p.FromDatabase([]int{1, 3})
So(err, ShouldBeNil)
})
Convey("Testing All", t, func() {
parts, err := All(0, 1, MockedDTX)
So(err, ShouldBeNil)
So(len(parts), ShouldEqual, 1)
So(parts, ShouldHaveSameTypeAs, []Part{})
})
Convey("Testing GetLatest", t, func() {
parts, err := Latest(10, MockedDTX)
So(err, ShouldBeNil)
So(len(parts), ShouldEqual, 10)
So(parts, ShouldHaveSameTypeAs, []Part{})
So(parts[0].DateAdded.String(), ShouldBeGreaterThan, parts[8].DateAdded.String())
})
Convey("Testing Featured", t, func() {
parts, err := Featured(3, MockedDTX)
So(err, ShouldBeNil)
So(len(parts), ShouldEqual, 3)
So(parts, ShouldHaveSameTypeAs, []Part{})
})
Convey("Testing Related", t, func() {
p := Part{
ID: 11000,
}
p.Get(MockedDTX)
parts, err := p.GetRelated(MockedDTX)
So(err, ShouldBeNil)
So(parts, ShouldHaveSameTypeAs, []Part{})
})
Convey("Get BY Old Part Number", t, func() {
p := Part{
OldPartNumber: "BM01821501",
}
err = p.GetPartByOldPartNumber()
So(err, ShouldBeNil)
})
_ = apicontextmock.DeMock(MockedDTX)
}