本文整理汇总了Golang中github.com/jpfielding/gotest/testutils.Ok函数的典型用法代码示例。如果您正苦于以下问题:Golang Ok函数的具体用法?Golang Ok怎么用?Golang Ok使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Ok函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSearchCompactParseCompact
func TestSearchCompactParseCompact(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(compactDecoded))
cr, err := NewCompactSearchResult(body)
testutils.Ok(t, err)
testutils.Assert(t, StatusOK == cr.Response.Code, "bad code")
testutils.Assert(t, "V2.7.0 2315: Success" == cr.Response.Text, "bad text")
testutils.Assert(t, 10 == int(cr.Count), "bad count")
testutils.Assert(t, 6 == len(cr.Columns), "bad header count")
testutils.Assert(t, "A,B,C,D,E,F" == strings.Join(cr.Columns, ","), "bad headers")
counter := 0
maxRows, err := cr.ForEach(func(row Row, err error) error {
if strings.Join(row, ",") != "1,2,3,4,,6" {
t.Errorf("bad row %d: %s", counter, row)
}
if err != nil {
t.Errorf("error parsing body at row %d: %s", counter, err.Error())
}
counter = counter + 1
return nil
})
testutils.Ok(t, err)
testutils.Assert(t, 8 == counter, "bad count")
testutils.Assert(t, maxRows, "bad max rows")
}
示例2: TestSearchXMLComplex
func TestSearchXMLComplex(t *testing.T) {
type Listing struct {
Business string `xml:"Business>RESIOWNS"`
Approved bool `xml:"Listing>Approved"`
MLS string `xml:"Listing>MLS"`
Disclaimer string `xml:"Listing>Disclaimer"`
Status string `xml:"Listing>Status"`
ListingPrice float64 `xml:"Listing>Price>ListingPrice"`
OriginalPrice float64 `xml:"Listing>Price>OriginalPrice"`
SellPrice float64 `xml:"Listing>Price>SellingPrice"`
}
body := ioutil.NopCloser(strings.NewReader(standardXML))
cr, err := NewStandardXMLSearchResult(body)
testutils.Ok(t, err)
var listings []Listing
count, maxRows, err := cr.ForEach(minidom.ByName("PropertyListing"), func(elem io.ReadCloser, err error) error {
if err != nil {
return err
}
listing := Listing{}
xml.NewDecoder(elem).Decode(&listing)
listings = append(listings, listing)
return err
})
testutils.Ok(t, err)
testutils.Equals(t, true, maxRows)
testutils.Equals(t, 10, count)
testutils.Equals(t, 2, len(listings))
}
示例3: TestConvertCompactMetadata
func TestConvertCompactMetadata(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(retsStart + system + resource + class + table + lookup + lookupType + retsEnd))
compact, err := rets.ParseMetadataCompactResult(body)
testutils.Ok(t, err)
msystem, err := AsStandard(*compact).Convert()
testutils.Ok(t, err)
testutils.Equals(t, "MLS System", msystem.System.Description)
testutils.Equals(t, "1.12.30", string(msystem.Version))
testutils.Equals(t, "The System is provided to you by Systems.", msystem.System.Comments)
mresource := msystem.System.MResource
testutils.Equals(t, "1.12.30", string(mresource.Version))
testutils.Equals(t, 2, len(mresource.Resource))
mlookup := mresource.Resource[1].MLookup
testutils.Equals(t, "1.12.29", string(mlookup.Version))
testutils.Equals(t, 4, len(mlookup.Lookup))
mlookupType := mlookup.Lookup[0].MLookupType
testutils.Equals(t, "1.12.29", string(mlookupType.Version))
testutils.Equals(t, 4, len(mlookupType.LookupType))
agent := mresource.Resource[1]
testutils.Equals(t, 2, len(agent.MClass.Class))
testutils.Equals(t, "Agent", string(agent.ResourceID))
testutils.Equals(t, "1.12.29", string(agent.MClass.Version))
}
示例4: TestParseCompactData
func TestParseCompactData(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(compact))
decoder := DefaultXMLDecoder(body, false)
token, err := decoder.Token()
testutils.Ok(t, err)
start, ok := token.(xml.StartElement)
testutils.Assert(t, ok, "should be a start element")
testutils.Equals(t, "METADATA-ELEMENT", start.Name.Local)
cm, err := NewCompactData(start, decoder, " ")
testutils.Ok(t, err)
testutils.Equals(t, "METADATA-ELEMENT", cm.Element)
testutils.Equals(t, "Dog", cm.Attr["Cat"])
testutils.Equals(t, 2, len(cm.CompactRows))
testutils.Equals(t, 2, len(cm.Columns()))
}
示例5: TestSimple
func TestSimple(t *testing.T) {
doms := ioutil.NopCloser(strings.NewReader(example))
parser := xml.NewDecoder(doms)
listings := Listings{}
// minidom isnt necessary but its crazy useful for massive streams
md := minidom.MiniDom{
StartFunc: func(start xml.StartElement) {
switch start.Name.Local {
case "Listings":
attrs := map[string]string{}
for _, v := range start.Attr {
attrs[v.Name.Local] = v.Value
}
listings.ListingsKey = attrs["listingsKey"]
listings.Version = attrs["version"]
listings.VersionTimestamp = attrs["versionTimestamp"]
listings.Language = attrs["lang"]
case "Disclaimer":
parser.DecodeElement(listings.Disclaimer, &start)
}
},
// quit on the the xml tag
EndFunc: minidom.QuitAt("Listings"),
}
err := md.Walk(parser, minidom.ByName("Listing"), ToListing(func(l Listing, err error) error {
listings.Listings = append(listings.Listings, l)
return err
}))
testutils.Ok(t, err)
testutils.Equals(t, 1, len(listings.Listings))
testutils.Equals(t, "http://www.somemls.com/lisings/1234567890", listings.Listings[0].ListingURL)
testutils.Equals(t, "New Light Fixtures", *listings.Listings[0].Photos[1].Caption)
testutils.Equals(t, "1100.0", listings.Listings[0].Expenses[2].Value.Value)
}
示例6: TestParseClass
func TestParseClass(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(retsStart + class + retsEnd))
ms, err := ParseMetadataCompactResult(body)
testutils.Ok(t, err)
verifyParseClass(t, *ms)
}
示例7: TestSearchXML
func TestSearchXML(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(standardXML))
cr, err := NewStandardXMLSearchResult(body)
testutils.Ok(t, err)
var listings []io.ReadCloser
count, maxRows, err := cr.ForEach(minidom.ByName("PropertyListing"), func(elem io.ReadCloser, err error) error {
listings = append(listings, elem)
return err
})
testutils.Ok(t, err)
testutils.Equals(t, true, maxRows)
testutils.Equals(t, 10, count)
testutils.Equals(t, 2, len(listings))
}
示例8: TestSearchCompactNoEof
func TestSearchCompactNoEof(t *testing.T) {
rets := `<RETS ReplyCode="20201" ReplyText="No Records Found." ></RETS>`
body := ioutil.NopCloser(strings.NewReader(rets))
cr, err := NewCompactSearchResult(body)
testutils.Ok(t, err)
testutils.Equals(t, StatusNoRecords, cr.Response.Code)
}
示例9: TestSystem
func TestSystem(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(raw))
defer body.Close()
extractor := &Extractor{Body: body}
response, err := extractor.Open()
testutils.Ok(t, err)
testutils.Equals(t, "Operation Successful", response.ReplyText)
xml := MSystem{}
err = extractor.DecodeNext("METADATA-SYSTEM", &xml)
if err != io.EOF {
testutils.Ok(t, err)
}
testutils.Equals(t, "ABBA", xml.System.ID)
testutils.Equals(t, "Property", string(xml.System.MResource.Resource[0].ResourceID))
}
示例10: TestCompactEntry
func TestCompactEntry(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(compact))
decoder := DefaultXMLDecoder(body, false)
token, err := decoder.Token()
testutils.Ok(t, err)
start, ok := token.(xml.StartElement)
testutils.Assert(t, ok, "should be a start element")
cm, err := NewCompactData(start, decoder, " ")
testutils.Ok(t, err)
type Test struct {
ResourceID, Standardname string
}
row1 := Test{}
maps := cm.Entries()
maps[0].SetFields(&row1)
testutils.Equals(t, "ActiveAgent", row1.ResourceID)
testutils.Equals(t, "ActiveAgent", row1.Standardname)
}
示例11: TestSearchCompactEmbeddedRetsStatus
func TestSearchCompactEmbeddedRetsStatus(t *testing.T) {
rets := `<?xml version="1.0" encoding="UTF-8" ?>
<RETS ReplyCode="0" ReplyText="Operation Successful">
<RETS-STATUS ReplyCode="20201" ReplyText="No matching records were found" />
</RETS>`
body := ioutil.NopCloser(strings.NewReader(rets))
cr, err := NewCompactSearchResult(body)
testutils.Ok(t, err)
testutils.Equals(t, StatusNoRecords, cr.Response.Code)
}
示例12: TestParseMetadata
func TestParseMetadata(t *testing.T) {
body := ioutil.NopCloser(strings.NewReader(retsStart + system + resource + class + table + lookup + lookupType + retsEnd))
ms, err := ParseMetadataCompactResult(body)
testutils.Ok(t, err)
verifySystem(t, *ms)
verifyParseResources(t, *ms)
verifyParseClass(t, *ms)
verifyParseTable(t, *ms)
verifyParseLookup(t, *ms)
verifyParseLookupType(t, *ms)
}
示例13: TestNext
func TestNext(t *testing.T) {
var raw = `<?xml version="1.0" encoding="utf-8"?>
<RETS ReplyCode="0" ReplyText="Operation successful.">
<METADATA>
<METADATA-CLASS Version="01.72.11582" Date="2016-03-29T21:50:11" Resource="Agent">
</METADATA-CLASS>
<METADATA-CLASS Version="01.72.11583" Date="2016-03-29T21:50:11" Resource="Office">
</METADATA-CLASS>
<METADATA-CLASS Version="01.72.11584" Date="2016-03-29T21:50:11" Resource="Listing">
</METADATA-CLASS>
</METADATA>
</RETS>`
body := ioutil.NopCloser(strings.NewReader(raw))
defer body.Close()
extractor := &Extractor{Body: body}
response, err := extractor.Open()
testutils.Ok(t, err)
testutils.Equals(t, "Operation successful.", response.ReplyText)
next := func(resource, version, date string) func(*testing.T) {
return func(tt *testing.T) {
mclass := &MClass{}
err = extractor.DecodeNext("METADATA-CLASS", mclass)
testutils.Ok(t, err)
testutils.Equals(tt, resource, string(mclass.Resource))
testutils.Equals(tt, version, string(mclass.Version))
testutils.Equals(tt, date, string(mclass.Date))
testutils.Equals(tt, 0, len(mclass.Class))
}
}
t.Run("agent", next("Agent", "01.72.11582", "2016-03-29T21:50:11"))
t.Run("offfice", next("Office", "01.72.11583", "2016-03-29T21:50:11"))
t.Run("listing", next("Listing", "01.72.11584", "2016-03-29T21:50:11"))
err = extractor.DecodeNext("METADATA-CLASS", &MClass{})
testutils.Equals(t, io.EOF, err)
}
示例14: TestSearchCompactBadChar
func TestSearchCompactBadChar(t *testing.T) {
rets := `<?xml version="1.0" encoding="UTF-8" ?>
<RETS ReplyCode="0" ReplyText="Operation Successful">
<COUNT Records="1" />
<DELIMITER value = "09"/>
<COLUMNS> A B C D E F </COLUMNS>
<DATA> 1` + "\x0b" + `1 2 3 4 6 </DATA>
</RETS>`
body := ioutil.NopCloser(strings.NewReader(rets))
cr, err := NewCompactSearchResult(body)
testutils.Ok(t, err)
testutils.Equals(t, StatusOK, cr.Response.Code)
counter := 0
cr.ForEach(func(row Row, err error) error {
testutils.Ok(t, err)
testutils.Equals(t, "1 1,2,3,4,,6", strings.Join(row, ","))
counter = counter + 1
return nil
})
}
示例15: TestSearchXMLBadChar
func TestSearchXMLBadChar(t *testing.T) {
type Listing struct {
Row string
}
rets := `<?xml version="1.0" encoding="UTF-8" ?>
<RETS ReplyCode="0" ReplyText="Operation Successful">
<COUNT Records="5" />
<Listings>
<PropertyListing>
<Row>bad` + "\x0b" + `row</Row>
</PropertyListing>
<PropertyListing>
<Row>good row</Row>
</PropertyListing>
</Listings>
<MAXROWS/>
</RETS>`
body := ioutil.NopCloser(strings.NewReader(rets))
cr, err := NewStandardXMLSearchResult(body)
testutils.Ok(t, err)
testutils.Equals(t, StatusOK, cr.Response.Code)
var listings []Listing
count, maxRows, err := cr.ForEach(minidom.ByName("PropertyListing"), func(elem io.ReadCloser, err error) error {
listing := Listing{}
xml.NewDecoder(elem).Decode(&listing)
listings = append(listings, listing)
return err
})
testutils.Ok(t, err)
testutils.Equals(t, true, maxRows)
testutils.Equals(t, 5, count)
testutils.Equals(t, 2, len(listings))
testutils.Equals(t, "bad row", listings[0].Row)
testutils.Equals(t, "good row", listings[1].Row)
}