From 86838c1fac1e6819120a1c618bcfa1c8c38664b1 Mon Sep 17 00:00:00 2001 From: Igor Shishkin Date: Sun, 5 Jan 2020 07:16:21 +0300 Subject: [PATCH] Add tests for Film::IsEmpty() Signed-off-by: Igor Shishkin --- types/film.go | 2 +- types/film_test.go | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 types/film_test.go diff --git a/types/film.go b/types/film.go index b22e5f1..27a0479 100644 --- a/types/film.go +++ b/types/film.go @@ -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 diff --git a/types/film_test.go b/types/film_test.go new file mode 100644 index 0000000..03cd765 --- /dev/null +++ b/types/film_test.go @@ -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 }