Skip to content

Commit

Permalink
Remove subtest from simple tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
  • Loading branch information
Kavindu-Dodan committed Jan 23, 2023
1 parent 021eca2 commit 764255f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 55 deletions.
40 changes: 19 additions & 21 deletions pkg/sync/file/filepath_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
65 changes: 31 additions & 34 deletions pkg/sync/http/http_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 764255f

Please sign in to comment.