From 156c7b295e156fdd749b2ec1749c85c78914cd79 Mon Sep 17 00:00:00 2001 From: Theresa Gresch Date: Thu, 14 May 2020 15:04:53 +0200 Subject: [PATCH] Backend: Add tests to internal/entity --- internal/entity/file_share_fixtures.go | 4 +-- internal/entity/file_share_fixtures_test.go | 36 +++++++++++++++++++++ internal/entity/file_sync_fixtures_test.go | 36 +++++++++++++++++++++ internal/entity/lens_fixtures_test.go | 34 +++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 internal/entity/file_share_fixtures_test.go create mode 100644 internal/entity/file_sync_fixtures_test.go create mode 100644 internal/entity/lens_fixtures_test.go diff --git a/internal/entity/file_share_fixtures.go b/internal/entity/file_share_fixtures.go index 45c90b63f..7d8f74372 100644 --- a/internal/entity/file_share_fixtures.go +++ b/internal/entity/file_share_fixtures.go @@ -27,7 +27,7 @@ var FileShareFixtures = FileShareMap{ FileID: 1000000, AccountID: 1000000, RemoteName: "name for remote", - Status: "test", + Status: FileShareShared, Error: "", Errors: 0, File: nil, @@ -39,7 +39,7 @@ var FileShareFixtures = FileShareMap{ FileID: 1000000, AccountID: 1000001, RemoteName: "name for remote", - Status: "test", + Status: FileShareNew, Error: "", Errors: 0, File: nil, diff --git a/internal/entity/file_share_fixtures_test.go b/internal/entity/file_share_fixtures_test.go new file mode 100644 index 000000000..4c53c4b8b --- /dev/null +++ b/internal/entity/file_share_fixtures_test.go @@ -0,0 +1,36 @@ +package entity + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestFileShareMap_Get(t *testing.T) { + t.Run("get existing fileshare", func(t *testing.T) { + r := FileShareFixtures.Get("FileShare1", 0, 0, "") + assert.Equal(t, uint(1000000), r.AccountID) + assert.Equal(t, "name for remote", r.RemoteName) + assert.IsType(t, FileShare{}, r) + }) + t.Run("get not existing fileshare", func(t *testing.T) { + r := FileShareFixtures.Get("FileShareXXX", 123, 888, "new remote name") + assert.Equal(t, uint(888), r.AccountID) + assert.Equal(t, "new remote name", r.RemoteName) + assert.IsType(t, FileShare{}, r) + }) +} + +func TestFileShareMap_Pointer(t *testing.T) { + t.Run("get existing fileshare pointer", func(t *testing.T) { + r := FileShareFixtures.Pointer("FileShare1", 0, 0, "") + assert.Equal(t, uint(1000000), r.AccountID) + assert.Equal(t, "name for remote", r.RemoteName) + assert.IsType(t, &FileShare{}, r) + }) + t.Run("get not existing fileshare pointer", func(t *testing.T) { + r := FileShareFixtures.Pointer("FileShareYYY", 456, 889, "new remote name for pointer") + assert.Equal(t, uint(889), r.AccountID) + assert.Equal(t, "new remote name for pointer", r.RemoteName) + assert.IsType(t, &FileShare{}, r) + }) +} diff --git a/internal/entity/file_sync_fixtures_test.go b/internal/entity/file_sync_fixtures_test.go new file mode 100644 index 000000000..1286747a2 --- /dev/null +++ b/internal/entity/file_sync_fixtures_test.go @@ -0,0 +1,36 @@ +package entity + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestFileSyncMap_Get(t *testing.T) { + t.Run("get existing filesync", func(t *testing.T) { + r := FileSyncFixtures.Get("FileSync1", 0, "") + assert.Equal(t, uint(1000000), r.AccountID) + assert.Equal(t, "name for remote sync", r.RemoteName) + assert.IsType(t, FileSync{}, r) + }) + t.Run("get not existing filesync", func(t *testing.T) { + r := FileSyncFixtures.Get("FileSyncXXX", 123, "new remote name for sync") + assert.Equal(t, uint(123), r.AccountID) + assert.Equal(t, "new remote name for sync", r.RemoteName) + assert.IsType(t, FileSync{}, r) + }) +} + +func TestFileSyncMap_Pointer(t *testing.T) { + t.Run("get existing filesync pointer", func(t *testing.T) { + r := FileSyncFixtures.Pointer("FileSync1", 0, "") + assert.Equal(t, uint(1000000), r.AccountID) + assert.Equal(t, "name for remote sync", r.RemoteName) + assert.IsType(t, &FileSync{}, r) + }) + t.Run("get not existing filesync pointer", func(t *testing.T) { + r := FileSyncFixtures.Pointer("FileSyncYYY", 456, "new remote name for sync pointer") + assert.Equal(t, uint(456), r.AccountID) + assert.Equal(t, "new remote name for sync pointer", r.RemoteName) + assert.IsType(t, &FileSync{}, r) + }) +} diff --git a/internal/entity/lens_fixtures_test.go b/internal/entity/lens_fixtures_test.go new file mode 100644 index 000000000..b75e680d1 --- /dev/null +++ b/internal/entity/lens_fixtures_test.go @@ -0,0 +1,34 @@ +package entity + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestLensMap_Get(t *testing.T) { + t.Run("get existing lens", func(t *testing.T) { + r := LensFixtures.Get("lens-f-380") + assert.Equal(t, uint(1000000), r.ID) + assert.Equal(t, "lens-f-380", r.LensSlug) + assert.IsType(t, Lens{}, r) + }) + t.Run("get not existing lens", func(t *testing.T) { + r := LensFixtures.Get("Lens 123") + assert.Equal(t, "lens-123", r.LensSlug) + assert.IsType(t, Lens{}, r) + }) +} + +func TestLensMap_Pointer(t *testing.T) { + t.Run("get existing lens pointer", func(t *testing.T) { + r := LensFixtures.Pointer("lens-f-380") + assert.Equal(t, uint(1000000), r.ID) + assert.Equal(t, "lens-f-380", r.LensSlug) + assert.IsType(t, &Lens{}, r) + }) + t.Run("get not existing lens pointer", func(t *testing.T) { + r := LensFixtures.Pointer("Lens new") + assert.Equal(t, "lens-new", r.LensSlug) + assert.IsType(t, &Lens{}, r) + }) +}