From c715e98a2dce87d216d5fb3299eaa2a2764c73ad Mon Sep 17 00:00:00 2001 From: Mauro Antonio Sanz Date: Fri, 25 Oct 2024 12:47:05 -0300 Subject: [PATCH] adding test --- .../api/large_segment_http_fetcher_test.go | 42 +++++++++++++++++++ .../proxy/service/api/testdata/ls_wrong.csv | 24 +++++++++++ 2 files changed, 66 insertions(+) create mode 100644 splitio/proxy/service/api/testdata/ls_wrong.csv diff --git a/splitio/proxy/service/api/large_segment_http_fetcher_test.go b/splitio/proxy/service/api/large_segment_http_fetcher_test.go index ac6e3aec..9899fb42 100644 --- a/splitio/proxy/service/api/large_segment_http_fetcher_test.go +++ b/splitio/proxy/service/api/large_segment_http_fetcher_test.go @@ -16,6 +16,48 @@ import ( "github.com/stretchr/testify/assert" ) +func TestFetchCsvMultipleColumns(t *testing.T) { + logger := logging.NewLogger(&logging.LoggerOptions{}) + + test_csv, _ := os.ReadFile("testdata/ls_wrong.csv") + fileServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write(test_csv) + })) + defer fileServer.Close() + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + data, _ := json.Marshal(dtos.RfeDTO{ + Params: dtos.ParamsDTO{ + Method: "GET", + URL: fileServer.URL, + }, + Format: Csv, + TotalKeys: 1500, + Size: 100, + ChangeNumber: 100, + Name: "large_segment_test", + Version: "1.0", + }) + w.Write(data) + })) + defer ts.Close() + + fetcher := NewHTTPLargeSegmentFetcher( + "api-key", + "1.0", + cmnConf.AdvancedConfig{ + EventsURL: ts.URL, + SdkURL: ts.URL, + }, + logger, + cmnDTOs.Metadata{}, + ) + + lsData, err := fetcher.Fetch("large_segment_test", &cmnService.SegmentRequestParams{}) + assert.Equal(t, "unssuported file content. The file has multiple columns", err.Error()) + assert.Equal(t, (*dtos.LargeSegmentDTO)(nil), lsData) +} + func TestFetchCsvFormat(t *testing.T) { logger := logging.NewLogger(&logging.LoggerOptions{}) diff --git a/splitio/proxy/service/api/testdata/ls_wrong.csv b/splitio/proxy/service/api/testdata/ls_wrong.csv new file mode 100644 index 00000000..b201cb90 --- /dev/null +++ b/splitio/proxy/service/api/testdata/ls_wrong.csv @@ -0,0 +1,24 @@ +60dfc0eb-9c42-44ff-9bd6-bf3f6950d7b3, +dc4ed38a-e186-416a-8569-ea42b53a7ce3, +1fb8de44-0c2e-48e4-9fac-eed31bc9a364, +ee10b416-fe41-422d-a96b-2e8bd69b417a, +f02606dc-51cd-4d5e-b3d9-2dfdd4bbd6ed, +51b4cc8d-384b-4acc-908c-2d9528a9b717, +c102d9ec-270f-41db-9eae-003a6f03403f, +c6643997-8ca1-4fe7-8edb-0de3acb647e0, +24c2b841-3e9e-4fb9-827f-b3be38cc0ea8, +8e5b7e62-4568-4b72-8912-7c94758f51e9, +04bd967c-fe3e-4a61-9e2c-8847126995e9, +f9abe90d-0014-452b-b21b-119f6a52e756, +d528829f-c755-4e5f-b7e0-3801c82d0ffc, +09a98bca-1af2-4bdb-bc37-05d34cf7f342, +8a2c2eb4-3a05-4f39-b82f-b7946e4e3cb6, +47c59c2e-8250-4e94-ab6e-c6e96b45084e, +99ebaaab-5d32-47b4-9cff-948d84e2ee21, +1e1fb5e9-6550-459f-b572-152816a57959, +2dfeb27b-61e3-415f-ac97-f0c2676886ab, +0a99dcbf-42b1-49c1-956e-467379a5e651, +336b0b81-d616-4628-8fca-ad3f7dc4af38, +6a0d5162-19e4-4929-8056-4b1642c700fd, +19576397-49ea-4386-a340-88004af8b171, +5ac7dc04-0536-46f2-833f-5f4987e641fd \ No newline at end of file