Skip to content

Commit

Permalink
Fixed tests for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Davideo37 committed Apr 15, 2022
1 parent a85dc9e commit 7b37487
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func main() {

start := time.Now()

fmt.Println("Parsing .slideshow file...")
// Parse in the various pieces from the template
Images, Audios, Transitions, TransitionDurations, Timings, Motions := parseSlideshow(slideshowDirectory)
fmt.Println("Parsing completed...")
Expand Down Expand Up @@ -142,7 +143,9 @@ func removeFileNameFromDirectory(slideshowDirectory string) string {
template_directory := ""

if len(template_directory_split) == 1 {
template_directory = "./"
if runtime.GOOS != "windows" {
template_directory = "./"
}
} else {
for i := 0; i < len(template_directory_split)-1; i++ {
template_directory += template_directory_split[i] + "/"
Expand All @@ -158,7 +161,6 @@ func parseSlideshow(slideshowDirectory string) ([]string, []string, []string, []
TransitionDurations := []string{}
Timings := []string{}
Motions := [][][]float64{}
fmt.Println("Parsing .slideshow file...")
var slideshow = readData(slideshowDirectory)

template_directory := removeFileNameFromDirectory(slideshowDirectory)
Expand Down Expand Up @@ -380,8 +382,6 @@ func combineVideos(Images []string, Transitions []string, TransitionDurations []
fmt.Println("Creating video...")
cmd := exec.Command("ffmpeg", input_images...)

fmt.Println(cmd)

output, err := cmd.CombinedOutput()
checkCMDError(output, err)
}
Expand Down
20 changes: 11 additions & 9 deletions src/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ package main
import (
"fmt"
"os/exec"
"runtime"
"strings"
"testing"
)

var ffmpeg string

func init() {
cmd := exec.Command("which", "ffmpeg")
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("where", "ffmpeg")
} else {
cmd = exec.Command("which", "ffmpeg")
}
output, err := cmd.CombinedOutput()
checkCMDError(output, err)

Expand All @@ -22,15 +28,15 @@ func TestParse(t *testing.T) {

Images, Audios, Transitions, TransitionDurations, Timings, Motions := parseSlideshow(templateName)

expectedImages := []string{"../TestInput/Jn01.1-18-title.jpg", "../TestInput/./VB-John 1v1.jpg", "../TestInput/./VB-John 1v3.jpg", "../TestInput/./VB-John 1v4.jpg", "../TestInput/./VB-John 1v5a.jpg",
"../TestInput/./VB-John 1v5b.jpg", "../TestInput/./VB-John 1v6.jpg", "../TestInput/Gospel of John-credits.jpg"}
expectedImages := []string{"Jn01.1-18-title.jpg", "./VB-John 1v1.jpg", "./VB-John 1v3.jpg", "./VB-John 1v4.jpg", "./VB-John 1v5a.jpg",
"./VB-John 1v5b.jpg", "./VB-John 1v6.jpg", "Gospel of John-credits.jpg"}
for i := 0; i < len(expectedImages); i++ {
if expectedImages[i] != Images[i] {
t.Error(fmt.Sprintf("expected image filename to be %s, but got %s", expectedImages[i], Images[i]))
}
}

expectedAudios := []string{"../TestInput/./music-intro-Jn.mp3", "../TestInput/narration-j-001.mp3", "../TestInput/narration-j-001.mp3", "../TestInput/narration-j-001.mp3", "../TestInput/narration-j-001.mp3", "../TestInput/narration-j-001.mp3", "../TestInput/narration-j-001.mp3", ""}
expectedAudios := []string{"./music-intro-Jn.mp3", "narration-j-001.mp3", "narration-j-001.mp3", "narration-j-001.mp3", "narration-j-001.mp3", "narration-j-001.mp3", "narration-j-001.mp3", ""}
for i := 0; i < len(expectedAudios); i++ {
if expectedAudios[i] != Audios[i] {
t.Error(fmt.Sprintf("expected audio filename to be %s, but got %s", expectedAudios[i], Audios[i]))
Expand Down Expand Up @@ -127,7 +133,7 @@ func Test_scaleImages(t *testing.T) {

expectedOutput := "1280x720"

t.Log(output_string)
//t.Log(output_string)

if output_string != expectedOutput {
t.Error(fmt.Sprintf("expected image %s to have widthxheight = %s, but got %s", "Jn01.1-18-title.jpg", expectedOutput, output_string))
Expand Down Expand Up @@ -158,7 +164,6 @@ func Test_cmdCreateTempVideo(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fmt.Println(cmdCreateTempVideo(tt.args.ImageDirectory, tt.args.duration, tt.args.zoom_cmd, tt.args.finalOutputDirectory).String())
if got := cmdCreateTempVideo(tt.args.ImageDirectory, tt.args.duration, tt.args.zoom_cmd, tt.args.finalOutputDirectory).String(); got != tt.want.String() {
t.Errorf("cmdCreateTempVideo() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -246,7 +251,6 @@ func Test_cmdTrimLengthOfVideo(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fmt.Println(cmdTrimLengthOfVideo(tt.args.duration, tt.args.tempPath).String())
if got := cmdTrimLengthOfVideo(tt.args.duration, tt.args.tempPath).String(); got != tt.want.String() {
t.Errorf("cmdTrimLengthOfVideo() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -280,7 +284,6 @@ func Test_cmdAddBackgroundMusic(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fmt.Println(cmdAddBackgroundMusic(tt.args.backgroundAudioPath, tt.args.volume).String())
if got := cmdAddBackgroundMusic(tt.args.backgroundAudioPath, tt.args.volume).String(); got != tt.want.String() {
t.Errorf("cmdAddBackgroundMusic() = %v, want %v", got, tt.want)
}
Expand Down Expand Up @@ -309,7 +312,6 @@ func Test_cmdCopyFile(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fmt.Println(cmdCopyFile(tt.args.oldPath, tt.args.newPath).String())
if got := cmdCopyFile(tt.args.oldPath, tt.args.newPath).String(); got != tt.want.String() {
t.Errorf("cmdAddBackgroundMusic() = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 7b37487

Please sign in to comment.