Example #1
0
func TestCreateEpisodeData(t *testing.T) {
	recordedTime, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 18:02:01")
	videoManifest, err := extron.CreateVideoManifest(
		"SMP-351-0C-E9-4E",
		recordedTime,
		"London",
		"../data/sample_iPod.m4v",
		"00:01:25",
		"../data/01515171.jpg")

	if err != nil {
		t.Error(err)
	}

	episodeData := videoManifest.CreateEpisodeData()

	// Test dcterms:created
	expectedCreated := "2015-01-01T18:02:01Z"
	created := episodeData.Created

	if created != expectedCreated {
		t.Errorf("Expected %v, got %v.", expectedCreated, created)
	}

	// Test dcterms:identifier
	expectedIdentifier := "SMP-351-0C-E9-4E_20150101-180201Z"
	id := episodeData.Identifier

	if id != expectedIdentifier {
		t.Errorf("Expected %v, got %v.", expectedIdentifier, id)
	}
}
Example #2
0
func TestCreateFiles(t *testing.T) {
	injestLocation, err := ioutil.TempDir(os.TempDir(), "extron")
	if err != nil {
		t.Error(err)
	}
	fmt.Println(injestLocation)
	defer os.RemoveAll(injestLocation)

	recordedTime, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 18:02:01")
	videoManifest, err := extron.CreateVideoManifest(
		"SMP-351-0C-E9-4E",
		recordedTime,
		"London",
		"../data/sample_iPod.m4v",
		"00:01:25",
		"../data/01515171.jpg")

	if err != nil {
		t.Error(err)
	}

	err = videoManifest.CreateFiles(injestLocation)
	if err != nil {
		t.Error(err)
	}

	// Assert manifest file exists
	tempDir := path.Join(injestLocation, videoManifest.GetPrefix())
	manifestFile := path.Join(tempDir, fmt.Sprintf("%v.json", videoManifest.GetPrefix()))
	if !extron.FileExists(manifestFile) {
		t.Errorf("Missing manifest file: %v", manifestFile)
	}

	// Assert video file has been copied
	videoFile := path.Join(tempDir, fmt.Sprintf("%v_S1R1.m4v", videoManifest.GetPrefix()))
	if !extron.FileExists(videoFile) {
		t.Errorf("Missing video file: %v", videoFile)
	}

	// Assert episode.xml exists
	episodeFile := path.Join(tempDir, "episode.xml")
	if !extron.FileExists(episodeFile) {
		t.Errorf("Missing video file: %v", episodeFile)
	}

	// Assert thumbnail exists
	thumbnail := path.Join(tempDir, "thumbnails", "01515171.jpg")
	if !extron.FileExists(thumbnail) {
		t.Errorf("Missing thumbnail file: %v", thumbnail)
	}

	// Assert xfer_complete exists
	xfer_complete := path.Join(tempDir, "xfer_complete")
	if !extron.FileExists(xfer_complete) {
		t.Errorf("Missing xfer_complete file: %v", xfer_complete)
	}
}
Example #3
0
func TestCreateEpisodeXml(t *testing.T) {
	recordedTime, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 18:02:01")
	videoManifest, err := extron.CreateVideoManifest(
		"SMP-351-0C-E9-4E",
		recordedTime,
		"London",
		"../data/sample_iPod.m4v",
		"00:01:25",
		"../data/01515171.jpg")

	if err != nil {
		t.Error(err)
	}

	episodeData, err := videoManifest.CreateEpisodeXml()
	if err != nil {
		t.Error(err)
	}

	if episodeData == "" {
		t.Error("Episode xml was empty string")
	}

	var x extron.EpisodeXml
	err = xml.Unmarshal([]byte(episodeData), &x)
	if err != nil {
		t.Error(err)
	}

	// Test dcterms:created
	expectedCreated := "2015-01-01T18:02:01Z"
	created := x.Created

	if created != expectedCreated {
		t.Errorf("Expected %v, got %v.", expectedCreated, created)
	}

	// Test dcterms:identifier
	expectedIdentifier := "SMP-351-0C-E9-4E_20150101-180201Z"
	id := x.Id

	if id != expectedIdentifier {
		t.Errorf("Expected %v, got %v.", expectedIdentifier, id)
	}

	// Test dcterms:title
	expectedTitle := "SMP-351-0C-E9-4E_20150101-180201Z"
	title := x.Title

	if title != expectedTitle {
		t.Errorf("Expected %v, got %v.", expectedTitle, title)
	}
}
Example #4
0
func TestGetPrefix(t *testing.T) {
	recordedTime, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 18:02:01")
	videoManifest, err := extron.CreateVideoManifest(
		"SMP-351-0C-E9-4E",
		recordedTime,
		"London",
		"../data/sample_iPod.m4v",
		"00:01:25",
		"../data/01515171.jpg")

	if err != nil {
		t.Error(err)
	}

	expectedPrefix := "SMP-351-0C-E9-4E_20150101-180201Z"
	prefix := videoManifest.GetPrefix()

	if prefix != expectedPrefix {
		t.Errorf("Expected %v, got %v.", expectedPrefix, prefix)
	}
}
Example #5
0
func TestCreateJsonManifest(t *testing.T) {
	expectedPrefix := "SMP-351-0C-E9-4E_20150101-180201Z"
	recordedTime, _ := time.Parse("2006-01-02 15:04:05", "2015-01-01 18:02:01")
	videoManifest, err := extron.CreateVideoManifest(
		"SMP-351-0C-E9-4E",
		recordedTime,
		"London",
		"../data/sample_iPod.m4v",
		"00:01:25",
		"../data/01515171.jpg")
	if err != nil {
		t.Error(err)
	}

	manifest, err := videoManifest.CreateJsonManifest()

	if err != nil {
		t.Error(err)
	}

	var f interface{}
	d := json.NewDecoder(strings.NewReader(manifest))
	d.UseNumber()
	if err := d.Decode(&f); err != nil {
		fmt.Println("Fail to json decode mainfest")
		log.Fatal(err)
	}

	if err != nil {
		t.Error(err)
	}

	// Assert name
	p := f.(map[string]interface{})["package"].(map[string]interface{})
	name := p["name"]
	if name != expectedPrefix {
		t.Errorf("Expected %v, got %v.", expectedPrefix, name)
	}

	// Assert location
	location := p["location"]
	if location != "London" {
		t.Errorf("Expected %v, got %v.", "London", location)
	}

	// Assert video filename
	streams := p["streams"].([]interface{})
	recording := streams[0].(map[string]interface{})["recordings"].([]interface{})[0].(map[string]interface{})
	expectedVideoName := fmt.Sprintf("%v_%v", expectedPrefix, "S1R1.m4v")
	videoName := recording["name"]

	if videoName != expectedVideoName {
		t.Errorf("Expected %v, got %v.", expectedVideoName, videoName)
	}

	// Recordings created date
	created := recording["created"]
	expectedCreated := "Thu Jan 1 18:02:01"
	if created != expectedCreated {
		t.Errorf("Expected %v, got %v.", expectedCreated, created)
	}

	// Test duration
	duration := recording["duration"]
	expectedDuration := "00:01:25"
	if duration != expectedDuration {
		t.Errorf("Expected %v, got %v.", expectedDuration, duration)
	}

	// Test recording size
	size, _ := recording["file_size"].(json.Number).Int64()
	expectedSize := int64(2236480)
	if size != expectedSize {
		t.Errorf("Expected %v, got %v.", expectedSize, size)
	}

	// Test duration
	thumbnails := streams[0].(map[string]interface{})["thumbnails"].([]interface{})[0].(map[string]interface{})
	thumbnail := thumbnails["name"]
	expectedThumbnail := "01515171.jpg"
	if thumbnail != expectedThumbnail {
		t.Errorf("Expected %v, got %v.", expectedThumbnail, thumbnail)
	}

	// Test local_time
	localTime := p["local_time"]
	excpectedLocalTime := "Thu Jan 1 18:02:01 2015"
	if localTime != excpectedLocalTime {
		t.Errorf("Expected %v, got %v.", excpectedLocalTime, localTime)
	}

	// Test utc_time
	utcTime := p["utc_time"]
	excpectedUTCTime := "Thu Jan 1 18:02:01 2015"
	if utcTime != excpectedUTCTime {
		t.Errorf("Expected %v, got %v.", excpectedUTCTime, utcTime)
	}

	// Test dc:identifier
	metaData := p["metadata"].(map[string]interface{})
	dcIdentifier := metaData["dc:identifier"]
	expectedDcIdentifier := expectedPrefix

	if dcIdentifier != expectedDcIdentifier {
		t.Errorf("Expected %v, got %v.", expectedDcIdentifier, dcIdentifier)
	}

	// Test dc:date
	dcDate := metaData["dc:date"]

	if dcDate != excpectedUTCTime {
		t.Errorf("Expected %v, got %v.", excpectedUTCTime, dcDate)
	}

	// Test package_size
	packageSize, _ := p["package_size"].(json.Number).Int64()
	expectedPackageSize := int64(2309763)
	if packageSize != expectedPackageSize {
		t.Errorf("Expected %v, got %v.", expectedPackageSize, packageSize)
	}
}