func createRecInfoTestCase(baseRec model.Recording) []recInfoTestCase { var testCases []recInfoTestCase // Recording did not start testCase := recInfoTestCase{ RecUpdate: recordingtbl.RecUpdate{UpdateParams: recordingtbl.RecParamA8, Rec: baseRec}, ExpHTTPStatusCode: http.StatusNotFound, ExpXMLStr: `<Response responseCode="1135" responseText="Capture of recording not yet started: ` + baseRec.XRID + `"></Response>`, } testCases = append(testCases, testCase) // Recording started, but did not end baseRec.ActualStartTime = baseRec.StartTime testCase = recInfoTestCase{ RecUpdate: recordingtbl.RecUpdate{UpdateParams: recordingtbl.RecParamActualStartTime, Rec: baseRec}, ExpHTTPStatusCode: http.StatusOK, ExpXMLStr: `<RecordingInfoResult recordingId="` + baseRec.XRID + `" accountId="Account-1">` + `<RecordingInfo stationId="StationID-1" streamId="Stream-1" recordingAdzone="AdZone-1"></RecordingInfo>` + `<RecordingPlayList playlistId="RIO-8" bitrate="5850000" contentEncoding="MPEG4">` + `<RecordingSegment role="SHOW" captureStart="` + baseRec.ActualStartTime.Format(a8common.ISO8601FmtStr) + `">` + `<Location protocol="HTTP" url="` + originURL + `"></Location>` + `<ContentId idType="RIO" idValue="` + fmt.Sprintf("%d", baseRec.IRID) + `">` + `</ContentId></RecordingSegment></RecordingPlayList></RecordingInfoResult>`, } testCases = append(testCases, testCase) // Recording ended, baseRec.ActualEndTime = baseRec.EndTime testCase = recInfoTestCase{ RecUpdate: recordingtbl.RecUpdate{UpdateParams: recordingtbl.RecParamActualEndTime, Rec: baseRec}, ExpHTTPStatusCode: http.StatusOK, ExpXMLStr: `<RecordingInfoResult recordingId="` + baseRec.XRID + `" accountId="Account-1">` + `<RecordingInfo stationId="StationID-1" streamId="Stream-1" recordingAdzone="AdZone-1"></RecordingInfo>` + `<RecordingPlayList playlistId="RIO-8" bitrate="5850000" contentEncoding="MPEG4">` + `<RecordingSegment role="SHOW" captureStart="` + baseRec.ActualStartTime.Format(a8common.ISO8601FmtStr) + `" captureEnd="` + baseRec.ActualEndTime.Format(a8common.ISO8601FmtStr) + `">` + `<Location protocol="HTTP" url="` + originURL + `"></Location>` + `<ContentId idType="RIO" idValue="` + fmt.Sprintf("%d", baseRec.IRID) + `">` + `</ContentId></RecordingSegment></RecordingPlayList></RecordingInfoResult>`, } testCases = append(testCases, testCase) // Recording erased baseRec.ErasedTime = baseRec.ActualEndTime.Add(10 * time.Second) testCase = recInfoTestCase{ RecUpdate: recordingtbl.RecUpdate{UpdateParams: recordingtbl.RecParamErasedTime, Rec: baseRec}, ExpHTTPStatusCode: http.StatusNotFound, ExpXMLStr: `<Response responseCode="1136" responseText="Recording was not recorded, or has been deleted: ` + baseRec.XRID + `"></Response>`, } testCases = append(testCases, testCase) return testCases }
// ---- Function below simulates the external component: CPIS that interface with RM through C3 request ---- func testGetRecordingInfo() error { var err error rec := model.Recording{ AccountID: "Account-1", StationID: "StationID-1", AdZone: "AdZone-1", StreamID: "Stream-1", StartTime: time.Now(), EndTime: time.Now().Add(20 * time.Second), } rec.XRID = fmt.Sprintf("XRID-%d", time.Now().Unix()) recUpdate := recordingtbl.RecUpdate{ UpdateParams: recordingtbl.RecParamA8, Rec: rec, } // We need to add it to Mock MetaData first to obtain IRID rec.IRID, err = upsertRecToDB(recUpdate) if err != nil { return err } // Create test case using the base recording data testCases := createRecInfoTestCase(rec) for _, test := range testCases { // upsert recording to mock db _, err = upsertRecToDB(test.RecUpdate) if err != nil { return err } // send C3 request to recorder manager r, err := http.Get(rmServerURL + "/rm/RecordingInfo?recordingId=" + rec.XRID + "&contentEncoding=MPEG4") if err != nil { return err } bytes, _ := ioutil.ReadAll(r.Body) r.Body.Close() if r.StatusCode != test.ExpHTTPStatusCode { return fmt.Errorf("Expect http status code: %d, got %d", test.ExpHTTPStatusCode, r.StatusCode) } if string(bytes) != test.ExpXMLStr { return fmt.Errorf("Received body:%s, expect:%s", string(bytes), test.ExpXMLStr) } } //end for return nil }