Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Add tests for Film::IsEmpty()
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <[email protected]>
  • Loading branch information
teran committed Jan 5, 2020
1 parent ff46b4b commit 86838c1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/film.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (f *Film) IsEmpty() bool {
return false
case f.Title != nil:
return false
case !f.FilmLoadedTimestamp.IsZero():
case f.FilmLoadedTimestamp != nil && !f.FilmLoadedTimestamp.IsZero():
return false
case f.FrameCount != nil:
return false
Expand Down
74 changes: 74 additions & 0 deletions types/film_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package types

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestFilmIsEmpty(t *testing.T) {
r := require.New(t)

type testCase struct {
name string
filmSample Film
expResult bool
}

tcs := []testCase{
{
name: "id filled",
filmSample: Film{ID: ptrInt64(1234)},
expResult: false,
},
{
name: "camera id filled",
filmSample: Film{CameraID: ptrInt64(1234)},
expResult: false,
},
{
name: "title filled",
filmSample: Film{Title: ptrString("test titme")},
expResult: false,
},
{
name: "timestamp filled",
filmSample: Film{FilmLoadedTimestamp: ptrTime(time.Now())},
expResult: false,
},
{
name: "frame count filled",
filmSample: Film{FrameCount: ptrInt64(1234)},
expResult: false,
},
{
name: "iso filled",
filmSample: Film{ISO: ptrInt64(1234)},
expResult: false,
},
{
name: "string filled",
filmSample: Film{Remarks: ptrString("blah")},
expResult: false,
},
{
name: "frames are present",
filmSample: Film{Frames: []*Frame{{}}},
expResult: false,
},
{
name: "empty film",
filmSample: Film{},
expResult: true,
},
}

for _, tc := range tcs {
r.Equalf(tc.expResult, tc.filmSample.IsEmpty(), tc.name)
}
}

func ptrInt64(t int64) *int64 { return &t }
func ptrString(t string) *string { return &t }
func ptrTime(t time.Time) *time.Time { return &t }

0 comments on commit 86838c1

Please sign in to comment.