Tests: Add file fixture

This commit is contained in:
theresa 2021-08-26 17:24:48 +02:00
parent a2671b3428
commit cfa105d3d6
2 changed files with 92 additions and 1 deletions

View file

@ -4,7 +4,25 @@ import (
"time"
)
var FileFixtures = map[string]File{
type FileMap map[string]File
func (m FileMap) Get(name string) File {
if result, ok := m[name]; ok {
return result
}
return File{FileName: name}
}
func (m FileMap) Pointer(name string) *File {
if result, ok := m[name]; ok {
return &result
}
return &File{FileName: name}
}
var FileFixtures = FileMap{
"exampleFileName.jpg": {
ID: 1000000,
Photo: PhotoFixtures.Pointer("19800101_000002_D640C559"),
@ -1115,6 +1133,45 @@ var FileFixtures = map[string]File{
UpdatedIn: 935962,
DeletedAt: nil,
},
"FileWithoutPhoto.mp4": {
ID: 1000031,
PhotoUID: "",
InstanceID: "",
FileUID: "ft2es49qhhinlpln",
FileName: "FileWithoutPhoto.mp4",
FileRoot: RootOriginals,
OriginalName: "",
FileHash: "pcad9a68fa6acc5c5ba965adf6ec465ca42fd916",
FileSize: 900,
FileCodec: "avc1",
FileType: "mp4",
FileMime: "video/mp4",
FilePrimary: false,
FileSidecar: false,
FileVideo: true,
FileMissing: false,
FilePortrait: false,
FileDuration: 115000000000,
FileWidth: 200,
FileHeight: 1100,
FileOrientation: 6,
FileProjection: "",
FileAspectRatio: 2,
FileMainColor: "red",
FileColors: "225221C1E",
FileLuminance: "DC42844C8",
FileDiff: 986,
FileChroma: 32,
FileError: "",
Share: []FileShare{},
Sync: []FileSync{},
ModTime: time.Date(2020, 12, 6, 2, 6, 51, 0, time.UTC).Unix(),
CreatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
CreatedIn: 935962,
UpdatedAt: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
UpdatedIn: 935962,
DeletedAt: nil,
},
}
var FileFixturesExampleJPG = FileFixtures["exampleFileName.jpg"]

View file

@ -0,0 +1,34 @@
package entity
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestFileMap_Get(t *testing.T) {
t.Run("get existing file", func(t *testing.T) {
r := FileFixtures.Get("exampleFileName.jpg")
assert.Equal(t, "ft8es39w45bnlqdw", r.FileUID)
assert.Equal(t, "2790/07/27900704_070228_D6D51B6C.jpg", r.FileName)
assert.IsType(t, File{}, r)
})
t.Run("get not existing file", func(t *testing.T) {
r := FileFixtures.Get("TestName")
assert.Equal(t, "TestName", r.FileName)
assert.IsType(t, File{}, r)
})
}
func TestFileMap_Pointer(t *testing.T) {
t.Run("get existing file", func(t *testing.T) {
r := FileFixtures.Pointer("exampleFileName.jpg")
assert.Equal(t, "ft8es39w45bnlqdw", r.FileUID)
assert.Equal(t, "2790/07/27900704_070228_D6D51B6C.jpg", r.FileName)
assert.IsType(t, &File{}, r)
})
t.Run("get not existing file", func(t *testing.T) {
r := FileFixtures.Pointer("TestName")
assert.Equal(t, "TestName", r.FileName)
assert.IsType(t, &File{}, r)
})
}