Skip to content

Commit

Permalink
Test: Split 'validateStreams' into smaller functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthi-chaud committed May 31, 2024
1 parent 321bfd4 commit dd61fb4
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions ffprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ func Test_ProbeReader_Error(t *testing.T) {
}

func validateData(t *testing.T, data *ProbeData) {
validateStreams(t, data)
// Check some Tags
const testMajorBrand = "isom"
if data.Format.Tags.MajorBrand != testMajorBrand {
t.Errorf("MajorBrand format tag is not %s", testMajorBrand)
}

if val, err := data.Format.TagList.GetString("major_brand"); err != nil {
t.Errorf("retrieving major_brand tag errors: %v", err)
} else if val != testMajorBrand {
t.Errorf("MajorBrand format tag is not %s", testMajorBrand)
}

// test Format.Duration
duration := data.Format.Duration()
if duration.Seconds() != 5.312 {
t.Errorf("this video is 5.312s.")
}
// test Format.StartTime
startTime := data.Format.StartTime()
if startTime != time.Duration(0) {
t.Errorf("this video starts at 0s.")
}
validateChapters(t, data)
}

func validateStreams(t *testing.T, data *ProbeData) {
// test ProbeData.GetStream
stream := data.StreamType(StreamVideo)
if len(stream) != 1 {
Expand Down Expand Up @@ -158,30 +185,9 @@ func validateData(t *testing.T, data *ProbeData) {
if len(stream) != 3 {
t.Errorf("It should have three streams.")
}
}

// Check some Tags
const testMajorBrand = "isom"
if data.Format.Tags.MajorBrand != testMajorBrand {
t.Errorf("MajorBrand format tag is not %s", testMajorBrand)
}

if val, err := data.Format.TagList.GetString("major_brand"); err != nil {
t.Errorf("retrieving major_brand tag errors: %v", err)
} else if val != testMajorBrand {
t.Errorf("MajorBrand format tag is not %s", testMajorBrand)
}

// test Format.Duration
duration := data.Format.Duration()
if duration.Seconds() != 5.312 {
t.Errorf("this video is 5.312s.")
}
// test Format.StartTime
startTime := data.Format.StartTime()
if startTime != time.Duration(0) {
t.Errorf("this video starts at 0s.")
}

func validateChapters(t *testing.T, data *ProbeData) {
chapters := data.Chapters
if chapters == nil {
t.Error("Chapters List was nil")
Expand Down

0 comments on commit dd61fb4

Please sign in to comment.