From 4231353e44acc7b09016615d388e9f95546f887b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Ribeiro?= Date: Thu, 10 Nov 2016 22:35:24 -0500 Subject: [PATCH] db/redis: add test for FieldMap() method --- db/redis/storage/redis_test.go | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/db/redis/storage/redis_test.go b/db/redis/storage/redis_test.go index d6920c60..538fa7a9 100644 --- a/db/redis/storage/redis_test.go +++ b/db/redis/storage/redis_test.go @@ -11,6 +11,8 @@ import ( "sync" "testing" "time" + + "github.com/NYTimes/video-transcoding-api/db" ) func TestRedisClientRedisDefaultOptions(t *testing.T) { @@ -229,6 +231,45 @@ func TestSaveErrors(t *testing.T) { } } +func TestFieldMap(t *testing.T) { + storage, err := NewStorage(&Config{}) + if err != nil { + t.Fatal(err) + } + job := db.Job{ + ID: "job1", + ProviderJobID: "123abc", + SourceMedia: "http://nyt.net/source_here.mp4", + ProviderName: "encoding.com", + StreamingParams: db.StreamingParams{ + SegmentDuration: 10, + Protocol: "hls", + PlaylistFileName: "hls/playlist.m3u8", + }, + Outputs: []db.TranscodeOutput{ + {Preset: db.PresetMap{Name: "preset-1"}, FileName: "output1.m3u8"}, + {Preset: db.PresetMap{Name: "preset-2"}, FileName: "output2.m3u8"}, + }, + } + expected := map[string]string{ + "source": "http://nyt.net/source_here.mp4", + "jobID": "job1", + "providerName": "encoding.com", + "providerJobID": "123abc", + "streamingparams_segmentDuration": "10", + "streamingparams_protocol": "hls", + "streamingparams_playlistFileName": "hls/playlist.m3u8", + "creationTime": "0001-01-01T00:00:00Z", + } + result, err := storage.FieldMap(job) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(result, expected) { + t.Errorf("Wrong FieldMap. Want %#v. Got %#v.", result, expected) + } +} + func TestLoadStruct(t *testing.T) { storage, err := NewStorage(&Config{}) if err != nil {