From e38ecc38fe587941ca2f3bab6d4d7edec7a2727d Mon Sep 17 00:00:00 2001 From: Ashlie Martinez Date: Wed, 4 Oct 2023 15:52:58 -0700 Subject: [PATCH] Tests for serializing service/category Should be squashed into a prior commit. --- src/pkg/backup/backup_bases_test.go | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/pkg/backup/backup_bases_test.go diff --git a/src/pkg/backup/backup_bases_test.go b/src/pkg/backup/backup_bases_test.go new file mode 100644 index 000000000..f58d2ea13 --- /dev/null +++ b/src/pkg/backup/backup_bases_test.go @@ -0,0 +1,70 @@ +package backup + +import ( + "strings" + "testing" + + "github.com/alcionai/clues" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/src/internal/tester" + "github.com/alcionai/corso/src/pkg/path" +) + +type BackupBasesUnitSuite struct { + tester.Suite +} + +func TestBackupBasesUnitSuite(t *testing.T) { + suite.Run(t, &BackupBasesUnitSuite{Suite: tester.NewUnitSuite(t)}) +} + +func (suite *BackupBasesUnitSuite) TestReasonSerialization() { + table := []struct { + name string + input string + expectErr assert.ErrorAssertionFunc + expectService path.ServiceType + expectCategory path.CategoryType + }{ + { + name: "ProperFormat", + input: serviceCatString(path.ExchangeService, path.EmailCategory), + expectErr: assert.NoError, + expectService: path.ExchangeService, + expectCategory: path.EmailCategory, + }, + { + name: "MissingPrefix", + input: strings.TrimPrefix( + serviceCatString(path.ExchangeService, path.EmailCategory), + serviceCatPrefix), + expectErr: assert.Error, + }, + { + name: "MissingSeparator", + input: strings.ReplaceAll( + serviceCatString(path.ExchangeService, path.EmailCategory), + separator, + ""), + expectErr: assert.Error, + }, + } + + for _, test := range table { + suite.Run(test.name, func() { + t := suite.T() + + service, cat, err := serviceCatStringToTypes(test.input) + test.expectErr(t, err, clues.ToCore(err)) + + if err != nil { + return + } + + assert.Equal(t, test.expectService, service) + assert.Equal(t, test.expectCategory, cat) + }) + } +}