Exemple #1
0
func TestOutput(t *testing.T) {
	filename := "test.mp4"
	param := ff.NewParam("foo", "bar")
	set := ff.NewParamSet(param)
	var output ff.File = ff.NewOutput(filename, set)
	Convey("ff.NewOutput(string, *ff.ParamSet)", t, func() {
		Convey("should not return nil", func() {
			So(output, ShouldNotBeNil)
		})
	})
	Convey("ff.File.Slice() should return paramters in correct order", t, func() {
		expected := []string{"-foo", "bar", filename, "-y"}
		So(output.Slice(), ShouldResemble, expected)
	})
}
Exemple #2
0
func TestBaseFile(t *testing.T) {
	Convey("Can create ff.BaseFile w/ Filename and Params", t, func() {
		filename := "test.mp4"
		param := ff.NewParam("foo", "bar")
		set := ff.NewParamSet(param)
		base := ff.BaseFile{Filename: filename, Params: set}
		Convey("It should contain the inital paramters", func() {
			So(base.Params.Slice(), ShouldContain, "-foo")
			So(base.Params.Slice(), ShouldContain, "bar")
		})
		Convey("ff.BaseFile.Name() returns the Filename", func() {
			So(base.Name(), ShouldEqual, filename)
		})
		Convey("ff.BaseFile.AddParam(ff.Param) adds the param", func() {
			newParam := ff.NewParam("baz", "bing")
			base.AddParam(newParam)
			So(base.Params.Slice(), ShouldContain, "-baz")
			So(base.Params.Slice(), ShouldContain, "bing")
		})
	})
}
Exemple #3
0
Fichier : main.go Projet : xdave/ff
func main() {
	flag.Parse()

	if len(flag.Args()) == 0 {
		fmt.Println("Usage: example INFILE")
		return
	}

	filename := flag.Args()[0]

	input := ff.NewInput(
		filename,
		ff.NewParamSet(
			ff.NewParam("v", "quiet"),
			ff.NewParam("print_format", "json"),
			ff.NewParam("show_format", nil),
			ff.NewParam("show_streams", nil),
		),
	)

	cmdline, err := ff.NewCommand("ffprobe", input)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Calling", cmdline.Path, cmdline.Slice())

	out, err := exec.Command(cmdline.Path, cmdline.Slice()...).CombinedOutput()
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(out))
}
Exemple #4
0
func TestCommand(t *testing.T) {
	filename := "test.mp4"
	param := ff.NewParam("foo", "bar")
	set := ff.NewParamSet(param)
	var input ff.File = ff.NewInput(filename, set)
	var output ff.File = ff.NewOutput(filename, set)
	path := "ffmpeg"

	Convey("ff.NewCommand()", t, func() {
		Convey("Cannot call with empty command (input only)", func() {
			cmd, err := ff.NewCommand("", input)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
		Convey("Cannot call with empty command (input+output)", func() {
			cmd, err := ff.NewCommand("", input, output)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
		Convey("Can call with only input", func() {
			cmd, err := ff.NewCommand(path, input)
			So(cmd, ShouldNotBeNil)
			So(err, ShouldBeNil)
		})
		Convey("Returns error with no input", func() {
			cmd, err := ff.NewCommand(path, nil, output)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
			cmd, err = ff.NewCommand(path, nil)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
		Convey("Returns error no input or output", func() {
			cmd, err := ff.NewCommand(path, nil)
			So(cmd, ShouldBeNil)
			So(err, ShouldNotBeNil)
		})
	})
	Convey("ff.Command.Slice() input+output", t, func() {
		cmd, _ := ff.NewCommand(path, input, output)
		slice := cmd.Slice()
		Convey("Should not return nil", func() {
			So(slice, ShouldNotBeNil)
		})
		Convey("Should return a []string slice", func() {
			So(slice, ShouldHaveSameTypeAs, []string{})
		})
		Convey("Should resemble expected value", func() {
			expected := []string{
				"-foo", "bar", "-i", filename,
				"-foo", "bar", filename, "-y",
			}
			So(slice, ShouldResemble, expected)
		})
	})
	Convey("ff.Command.Slice() input only", t, func() {
		cmd, _ := ff.NewCommand(path, input)
		slice := cmd.Slice()
		Convey("Should not return nil", func() {
			So(slice, ShouldNotBeNil)
		})
		Convey("Should return a []string slice", func() {
			So(slice, ShouldHaveSameTypeAs, []string{})
		})
		Convey("Should resemble expected value", func() {
			expected := []string{
				"-foo", "bar", "-i", filename,
			}
			So(slice, ShouldResemble, expected)
		})
	})
}
Exemple #5
0
func TestNewParamSet(t *testing.T) {
	Convey("ff.NewParamSet(...ff.Param)", t, func() {
		Convey("Result should NOT be nil", func() {
			set := ff.NewParamSet()
			So(set, ShouldNotBeNil)
		})
		Convey("ff.ParamSet.Len()", func() {
			Convey("If passed no params", func() {
				set := ff.NewParamSet()
				Convey("set.Len() should be 0", func() {
					So(set.Len(), ShouldEqual, 0)
				})
			})
			Convey("If passed a param with nil key and value", func() {
				param := ff.NewParam(nil, nil)
				set := ff.NewParamSet(param)
				Convey("set.Len() should be 0", func() {
					So(set.Len(), ShouldEqual, 0)
				})
			})
			Convey("If passed a param with nil key and non-nil value", func() {
				param := ff.NewParam(nil, testValue)
				set := ff.NewParamSet(param)
				Convey("set.Len() should be 1", func() {
					So(set.Len(), ShouldEqual, 1)
				})
			})
			Convey("If passed a param with non-nil key and nil value", func() {
				param := ff.NewParam(testKey, nil)
				set := ff.NewParamSet(param)
				Convey("set.Len() should be 1", func() {
					So(set.Len(), ShouldEqual, 1)
				})
			})
			Convey("If passed a param with non-nil key and non-nil value", func() {
				param := ff.NewParam(testKey, testValue)
				set := ff.NewParamSet(param)
				Convey("set.Len() should be 2", func() {
					So(set.Len(), ShouldEqual, 2)
				})
			})
			Convey("If passed 2 params with non-nil key and non-nil value", func() {
				param1 := ff.NewParam(testKey, testValue)
				param2 := ff.NewParam(testKey, testValue)
				set := ff.NewParamSet(param1, param2)
				Convey("set.Len() should be 4", func() {
					So(set.Len(), ShouldEqual, 4)
				})
			})
		})
		Convey("ff.ParamSet.Add(ff.Param)", func() {
			Convey("If passed a Param with len() 0", func() {
				param := ff.NewParam(nil, nil)
				set := ff.NewParamSet()
				set.Add(param)
				Convey("set.Len() should be 0", func() {
					So(set.Len(), ShouldEqual, 0)
				})
			})
			Convey("If passed a Param with len() 1", func() {
				param := ff.NewParam(testKey, nil)
				set := ff.NewParamSet()
				set.Add(param)
				Convey("set.Len() should be 1", func() {
					So(set.Len(), ShouldEqual, 1)
				})
			})
			Convey("If passed 2 Params with len() 1", func() {
				param1 := ff.NewParam(testKey, nil)
				param2 := ff.NewParam(nil, testValue)
				set := ff.NewParamSet()
				set.Add(param1, param2)
				Convey("set.Len() should be 2", func() {
					So(set.Len(), ShouldEqual, 2)
				})
			})
		})
		Convey("ff.ParamSet.Slice()", func() {
			Convey("Given 3 len(2) Params", func() {
				param1 := ff.NewParam(testKey, testValue)
				param2 := ff.NewParam(testKey, testValue)
				param3 := ff.NewParam(testKey, testValue)
				set := ff.NewParamSet(param1, param2)
				set.Add(param3)
				result := set.Slice()
				Convey("Calling Slice() should yield []string", func() {
					So(result, ShouldHaveSameTypeAs, []string{})
				})
				Convey("Result should not be empty", func() {
					So(result, ShouldNotBeEmpty)
				})
				Convey("set.Len() should equal number of actual items", func() {
					So(set.Len(), ShouldEqual, len(result))
				})
				Convey("result should resemble expected value", func() {
					So(result, ShouldResemble,
						[]string{
							"-" + testKey,
							testValue,
							"-" + testKey,
							testValue,
							"-" + testKey,
							testValue})
				})
			})
		})
	})
}