func TestGetObjects(t *testing.T) { extracted := extractBoundary(contentType) testutils.Equals(t, boundary, extracted) body := ioutil.NopCloser(bytes.NewReader([]byte(multipartBody))) quit := make(chan struct{}) defer close(quit) results := parseGetObjectsResult(quit, extracted, body) r1 := <-results testutils.Ok(t, r1.Err) o1 := r1.Object testutils.Equals(t, true, o1.Preferred) testutils.Equals(t, "image/jpeg", o1.ContentType) testutils.Equals(t, "123456", o1.ContentId) testutils.Equals(t, 1, o1.ObjectId) testutils.Equals(t, "<binary data 1>", string(o1.Blob)) testutils.Equals(t, "123456", o1.ObjectData["ListingKey"]) testutils.Equals(t, "2013-05-01T12:34:34.8-0500", o1.ObjectData["ListDate"]) r2 := <-results testutils.Ok(t, r2.Err) o2 := r2.Object testutils.Equals(t, 2, o2.ObjectId) testutils.Equals(t, "1a234234234", o2.Uid) r3 := <-results testutils.Ok(t, r3.Err) o3 := r3.Object testutils.Equals(t, 3, o3.ObjectId) testutils.Equals(t, "Outhouse", o3.Description) testutils.Equals(t, "The urinal", o3.SubDescription) r4 := <-results testutils.Ok(t, r4.Err) o4 := r4.Object testutils.Equals(t, true, o4.RetsError) testutils.Equals(t, "text/xml", o4.ContentType) testutils.Equals(t, "There is no object with that Object-ID", o4.RetsErrorMessage.ReplyText) testutils.Equals(t, 20403, o4.RetsErrorMessage.ReplyCode) r5 := <-results testutils.Ok(t, r5.Err) o5 := r5.Object testutils.Equals(t, "http://www.simpleboundary.com/image-5.jpg", o5.Location) testutils.Equals(t, "image/jpeg", o5.ContentType) testutils.Equals(t, "123456", o5.ContentId) testutils.Equals(t, 5, o5.ObjectId) testutils.Equals(t, "<binary data 5>", string(o5.Blob)) }
func TestParseClass(t *testing.T) { body := ioutil.NopCloser(bytes.NewReader([]byte(retsStart + class + retsEnd))) ms, err := parseMetadataCompactResult(body) testutils.Ok(t, err) verifyParseClass(t, *ms) }
func TestParseCapabilitiesRelativeUrls(t *testing.T) { body := `<RETS ReplyCode="0" ReplyText="V2.7.0 2315: Success"> <RETS-RESPONSE> MemberName=Threewide Corporation User=2000343, Association Member Primary:Login:Media Restrictions:Office:RETS:RETS Advanced:RETS Customer:System-MRIS:MDS Access Common:MDS Application Login, 90, TURD1 Broker=TWD,1 MetadataVersion=1.12.30 MinMetadataVersion=1.1.1 OfficeList=TWD;1 TimeoutSeconds=1800 Login=/platinum/login Action=/platinum/get?Command=Message Search=/platinum/search Get=/platinum/get GetObject=/platinum/getobject Logout=/platinum/logout GetMetadata=/platinum/getmetadata ChangePassword=/platinum/changepassword </RETS-RESPONSE> </RETS>` urls, err := parseCapability("http://server.com:6103/platinum/login", []byte(body)) testutils.Ok(t, err) testutils.Equals(t, urls.Response.ReplyText, "V2.7.0 2315: Success") testutils.Equals(t, urls.Response.ReplyCode, 0) testutils.Equals(t, urls.Login, "http://server.com:6103/platinum/login") testutils.Equals(t, urls.GetMetadata, "http://server.com:6103/platinum/getmetadata") }
func TestParseGetObjectQuit(t *testing.T) { extracted := extractBoundary(contentType) testutils.Equals(t, boundary, extracted) body := ioutil.NopCloser(bytes.NewReader([]byte(multipartBody))) quit := make(chan struct{}) defer close(quit) results := parseGetObjectsResult(quit, extracted, body) r1 := <-results testutils.Ok(t, r1.Err) testutils.Assert(t, r1 != GetObjectResult{}, "should not be the zerod object") o1 := r1.Object testutils.Equals(t, "image/jpeg", o1.ContentType) testutils.Equals(t, "123456", o1.ContentId) testutils.Equals(t, 1, o1.ObjectId) quit <- struct{}{} // the closed channel will emit a zero'd value of the proper type r2 := <-results testutils.Equals(t, r2, GetObjectResult{}) }
func TestGetObject(t *testing.T) { header := http.Header{} textproto.MIMEHeader(header).Add("Content-Type", "image/jpeg") textproto.MIMEHeader(header).Add("Content-ID", "123456") textproto.MIMEHeader(header).Add("Object-ID", "1") textproto.MIMEHeader(header).Add("Preferred", "1") textproto.MIMEHeader(header).Add("UID", "1a234234234") textproto.MIMEHeader(header).Add("Content-Description", "Outhouse") textproto.MIMEHeader(header).Add("Content-Sub-Description", "The urinal") textproto.MIMEHeader(header).Add("Location", "http://www.simpleboundary.com/image-5.jpg") var body string = `<binary data 1>` reader := ioutil.NopCloser(bytes.NewReader([]byte(body))) quit := make(chan struct{}) defer close(quit) results := parseGetObjectResult(quit, header, reader) result := <-results o := result.Object testutils.Ok(t, result.Err) testutils.Equals(t, true, o.Preferred) testutils.Equals(t, "image/jpeg", o.ContentType) testutils.Equals(t, "123456", o.ContentId) testutils.Equals(t, 1, o.ObjectId) testutils.Equals(t, "1a234234234", o.Uid) testutils.Equals(t, "Outhouse", o.Description) testutils.Equals(t, "The urinal", o.SubDescription) testutils.Equals(t, "<binary data 1>", string(o.Blob)) testutils.Equals(t, "http://www.simpleboundary.com/image-5.jpg", o.Location) testutils.Equals(t, false, o.RetsError) }
func TestParseMetadata(t *testing.T) { body := ioutil.NopCloser(bytes.NewReader([]byte(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) }
func verifyCompactData(t *testing.T, pl *PayloadList, id string) { payload := <-pl.Payloads testutils.Equals(t, 6, len(payload.Columns)) testutils.Equals(t, id, payload.Id) testutils.Equals(t, "A,B,C,D,E,F", strings.Join(payload.Columns, ",")) counter := 0 for _, row := range payload.Rows { testutils.Assert(t, strings.Join(row, ",") == "1,2,3,4,5,6", fmt.Sprintf("bad row %d: %s", counter, row)) testutils.Ok(t, pl.Error) counter = counter + 1 } testutils.Equals(t, 8, counter) }