Example #1
0
File: ff_test.go Project: xdave/ff
func TestNewParam(t *testing.T) {
	Convey("ff.NewParam(key, value interface{})", t, func() {
		for i, key := range testKeys {
			Convey(fmt.Sprintf("Given a '%T' key #%d", key, i), func() {
				param := ff.NewParam(key, nil)
				if fmt.Sprintf("%T", key) != "string" {
					Convey("Stored Key should be nil", func() {
						So(param.Key, ShouldBeNil)
					})
				} else {
					Convey("Stored Key should be a string", func() {
						So(param.Key, ShouldHaveSameTypeAs, "")
					})
				}
			})
		}
		for i, value := range testValues {
			Convey(fmt.Sprintf("With a '%T' value #%d", value, i), func() {
				param := ff.NewParam(testKey, value)
				Convey("Stored Value should same type", func() {
					So(param.Value, ShouldHaveSameTypeAs, value)
				})
			})
		}
	})
}
Example #2
0
File: ff_test.go Project: xdave/ff
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")
		})
	})
}
Example #3
0
File: main.go Project: 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))
}
Example #4
0
File: ff_test.go Project: xdave/ff
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)
	})
}
Example #5
0
File: ff_test.go Project: xdave/ff
func TestParamSlice(t *testing.T) {
	Convey("ff.Param.Slice()", t, func() {
		for i, key := range testKeys {
			Convey(fmt.Sprintf("With a '%T' key #%d", key, i), func() {
				param := ff.NewParam(key, testValue)
				slice := param.Slice()
				if fmt.Sprintf("%T", key) != "string" {
					Convey("The len() slice should be less than 2", func() {
						So(len(slice), ShouldBeLessThan, 2)
					})
				} else {
					Convey("The len() of slice should be at least 1", func() {
						So(len(slice), ShouldBeGreaterThanOrEqualTo, 1)
					})
					Convey("The first element", func() {
						first := slice[0]
						Convey("Shouldn't be empty", func() {
							So(first, ShouldNotBeEmpty)
						})
						Convey("Should start with '-'", func() {
							So(first, ShouldStartWith, "-")
						})
						Convey("Should end with string of key", func() {
							So(first, ShouldEndWith, fmt.Sprintf("%v", key))
						})
					})
				}
			})
		}
		Convey("For both nil key and nil value", func() {
			param := ff.NewParam(nil, nil)
			slice := param.Slice()
			Convey("slice should be empty", func() {
				So(slice, ShouldBeEmpty)
				Convey("len() of slice should be 0", func() {
					So(len(slice), ShouldEqual, 0)
				})
				Convey("slice should resemble []string{}", func() {
					So(slice, ShouldResemble, []string{})
				})
			})
		})
		Convey("For nil key and non-nil value", func() {
			param := ff.NewParam(nil, testValue)
			slice := param.Slice()
			Convey("slice should not be empty", func() {
				So(slice, ShouldNotBeEmpty)
				Convey("len() of slice should be 1", func() {
					So(len(slice), ShouldEqual, 1)
				})
				Convey("slice should resemble []string{testValue}", func() {
					So(slice, ShouldResemble, []string{testValue})
				})
			})
		})
		Convey("For non-nil key and nil value", func() {
			param := ff.NewParam(testKey, nil)
			slice := param.Slice()
			Convey("slice should not be empty", func() {
				So(slice, ShouldNotBeEmpty)
				Convey("len() of slice should be 1", func() {
					So(len(slice), ShouldEqual, 1)
				})
				Convey("slice should resemble []string{-testKey}", func() {
					So(slice, ShouldResemble, []string{"-" + testKey})
				})
			})
		})
		Convey("For both non-nil key and value", func() {
			param := ff.NewParam(testKey, testValue)
			slice := param.Slice()
			Convey("slice should not be empty", func() {
				So(slice, ShouldNotBeEmpty)
				Convey("len() of slice should be 2", func() {
					So(len(slice), ShouldEqual, 2)
				})
				Convey("slice should resemble []string{-testKey, testValue}", func() {
					So(slice, ShouldResemble, []string{"-" + testKey, testValue})
				})
			})
		})
	})
}
Example #6
0
File: ff_test.go Project: xdave/ff
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)
		})
	})
}
Example #7
0
File: ff_test.go Project: xdave/ff
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})
				})
			})
		})
	})
}