From 764255f34f741a04c34df371ff08183af967ac3a Mon Sep 17 00:00:00 2001 From: Kavindu Dodanduwa Date: Fri, 20 Jan 2023 07:21:05 -0800 Subject: [PATCH] Remove subtest from simple tests Signed-off-by: Kavindu Dodanduwa --- pkg/sync/file/filepath_sync_test.go | 40 +++++++++--------- pkg/sync/http/http_sync_test.go | 65 ++++++++++++++--------------- 2 files changed, 50 insertions(+), 55 deletions(-) diff --git a/pkg/sync/file/filepath_sync_test.go b/pkg/sync/file/filepath_sync_test.go index 4fe943009..3998e4eed 100644 --- a/pkg/sync/file/filepath_sync_test.go +++ b/pkg/sync/file/filepath_sync_test.go @@ -19,32 +19,30 @@ const ( ) func TestSimpleSync(t *testing.T) { - t.Run("SimpleSync", func(t *testing.T) { - handler := Sync{ - URI: fmt.Sprintf("%s/%s", dirName, fetchFileName), - Logger: logger.NewLogger(nil, false), - } + handler := Sync{ + URI: fmt.Sprintf("%s/%s", dirName, fetchFileName), + Logger: logger.NewLogger(nil, false), + } - defer t.Cleanup(cleanupFilePath) - setupFilePathFetch(t) + defer t.Cleanup(cleanupFilePath) + setupFilePathFetch(t) - ctx := context.Background() - dataSyncChan := make(chan sync.DataSync) + ctx := context.Background() + dataSyncChan := make(chan sync.DataSync) - go func() { - err := handler.Sync(ctx, dataSyncChan) - if err != nil { - log.Fatalf("Error start sync: %s", err.Error()) - return - } - }() + go func() { + err := handler.Sync(ctx, dataSyncChan) + if err != nil { + log.Fatalf("Error start sync: %s", err.Error()) + return + } + }() - data := <-dataSyncChan + data := <-dataSyncChan - if data.FlagData != fetchFileContents { - t.Errorf("Expected content %s, but received content %s", fetchFileContents, data.FlagData) - } - }) + if data.FlagData != fetchFileContents { + t.Errorf("Expected content %s, but received content %s", fetchFileContents, data.FlagData) + } } func TestFilePathSync_Fetch(t *testing.T) { diff --git a/pkg/sync/http/http_sync_test.go b/pkg/sync/http/http_sync_test.go index 075ec6341..55bfa005a 100644 --- a/pkg/sync/http/http_sync_test.go +++ b/pkg/sync/http/http_sync_test.go @@ -17,45 +17,42 @@ import ( func TestSimpleSync(t *testing.T) { ctrl := gomock.NewController(t) + resp := "test response" - t.Run("SimpleSync", func(t *testing.T) { - resp := "test response" - - mockCron := syncmock.NewMockCron(ctrl) - mockCron.EXPECT().AddFunc(gomock.Any(), gomock.Any()).DoAndReturn(func(spec string, cmd func()) error { - return nil - }) - mockCron.EXPECT().Start().Times(1) - - mockClient := syncmock.NewMockHTTPClient(ctrl) - mockClient.EXPECT().Do(gomock.Any()).Return(&http.Response{Body: io.NopCloser(strings.NewReader(resp))}, nil) - - httpSync := Sync{ - URI: "http://localhost", - Client: mockClient, - Cron: mockCron, - BearerToken: "", - LastBodySHA: "", - Logger: logger.NewLogger(nil, false), - } + mockCron := syncmock.NewMockCron(ctrl) + mockCron.EXPECT().AddFunc(gomock.Any(), gomock.Any()).DoAndReturn(func(spec string, cmd func()) error { + return nil + }) + mockCron.EXPECT().Start().Times(1) + + mockClient := syncmock.NewMockHTTPClient(ctrl) + mockClient.EXPECT().Do(gomock.Any()).Return(&http.Response{Body: io.NopCloser(strings.NewReader(resp))}, nil) + + httpSync := Sync{ + URI: "http://localhost", + Client: mockClient, + Cron: mockCron, + BearerToken: "", + LastBodySHA: "", + Logger: logger.NewLogger(nil, false), + } - ctx := context.Background() - dataSyncChan := make(chan sync.DataSync) + ctx := context.Background() + dataSyncChan := make(chan sync.DataSync) - go func() { - err := httpSync.Sync(ctx, dataSyncChan) - if err != nil { - log.Fatalf("Error start sync: %s", err.Error()) - return - } - }() + go func() { + err := httpSync.Sync(ctx, dataSyncChan) + if err != nil { + log.Fatalf("Error start sync: %s", err.Error()) + return + } + }() - data := <-dataSyncChan + data := <-dataSyncChan - if data.FlagData != resp { - t.Errorf("Expected content %s, but received content %s", resp, data.FlagData) - } - }) + if data.FlagData != resp { + t.Errorf("Expected content %s, but received content %s", resp, data.FlagData) + } } func TestHTTPSync_Fetch(t *testing.T) {