diff options
author | Matthew Lemon <y@yulqen.org> | 2024-04-19 20:51:48 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-04-19 20:51:48 +0100 |
commit | 04f78ef7a46ae4c4b8ab49153c16983c590783f5 (patch) | |
tree | 77825f91fb6175f300c2667be4c9a91b19aab417 /cmd/dbasik-api/datamaps_test.go | |
parent | 85d77655a515c120e5c0ba3c48c6be4eda1ac8f6 (diff) |
First parse of an Excel file
Diffstat (limited to 'cmd/dbasik-api/datamaps_test.go')
-rw-r--r-- | cmd/dbasik-api/datamaps_test.go | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/cmd/dbasik-api/datamaps_test.go b/cmd/dbasik-api/datamaps_test.go index 428f301..827a054 100644 --- a/cmd/dbasik-api/datamaps_test.go +++ b/cmd/dbasik-api/datamaps_test.go @@ -6,45 +6,53 @@ import ( "time" ) -func TestReadDML(t *testing.T) { - dm := datamap{ - ID: 0, - Name: "Test Name", - Description: "Test description", - Created: time.Now(), - DMLs: []datamapLine{ - { - ID: 1, - Key: "Test Key", - Sheet: "Test Sheet", - DataType: "TEXT", - Cellref: "A10", - }, - { - ID: 2, - Key: "Test Key 2", - Sheet: "Test Sheet", - DataType: "TEXT", - Cellref: "A11", - }, - { - ID: 3, - Key: "Test Key 3", - Sheet: "Test Sheet 2", - DataType: "TEXT", - Cellref: "A12", +func TestGetSheetsFromDM(t *testing.T) { + testCases := []struct { + name string + datamap Datamap + expected []string + }{ + { + name: "Extract unique sheet names", + datamap: Datamap{ + ID: 0, + Name: "Test Name", + Description: "Test description", + Created: time.Now(), + DMLs: []DatamapLine{ + { + ID: 1, + Key: "Test Key", + Sheet: "Test Sheet", + DataType: "TEXT", + CellRef: "A10", + }, + { + ID: 2, + Key: "Test Key 2", + Sheet: "Test Sheet", + DataType: "TEXT", + CellRef: "A11", + }, + { + ID: 3, + Key: "Test Key 3", + Sheet: "Test Sheet 2", + DataType: "TEXT", + CellRef: "A12", + }, + }, }, + expected: []string{"Test Sheet", "Test Sheet 2"}, }, } - got := GetSheetsFromDM(dm) - if !slices.Contains(got, "Test Sheet") { - t.Errorf("expected to find Test Sheet in %v but didn't find it", got) - } - if !slices.Contains(got, "Test Sheet 2") { - t.Errorf("expected to find Test Sheet in %v but didn't find it", got) - } - if slices.Contains(got, "Test Sheet 3") { - t.Errorf("expected to find Test Sheet in %v but didn't find it", got) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got := GetSheetsFromDM(tc.datamap) + if !slices.Equal(got, tc.expected) { + t.Errorf("GetSheetsFromDM(%v) = %v, expected %v", tc.datamap, got, tc.expected) + } + }) } } |