Skip to content

Commit

Permalink
updated the flow to correspond to the sequence diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveromahony committed Nov 14, 2024
1 parent 09cb7b1 commit d239511
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 15 additions & 8 deletions internal/file/file_manager_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"errors"
"fmt"
"log/slog"
"maps"
"os"
"slices"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -133,14 +135,6 @@ func (fms *FileManagerService) UpdateOverview(
return nil, validatedError
}

response.Overview = &mpi.FileOverview{
Files: filesToUpdate,
ConfigVersion: &mpi.ConfigVersion{
InstanceId: instanceID,
Version: files.GenerateConfigVersion(filesToUpdate),
},
}

return response, nil
}

Expand All @@ -154,6 +148,19 @@ func (fms *FileManagerService) UpdateOverview(

slog.DebugContext(newCtx, "UpdateOverview response", "response", response)

// calculate the response.Overview delta vs what is on disk
delta, _, compareErr := fms.DetermineFileActions(fms.currentFilesOnDisk,
files.ConvertToMapOfFiles(response.GetOverview().GetFiles()))

if compareErr != nil {
return compareErr
}

if len(delta) != 0 {
diffFiles := slices.Collect(maps.Values(delta))
return fms.UpdateOverview(ctx, instanceID, diffFiles)
}

return err
}

Expand Down
6 changes: 4 additions & 2 deletions internal/file/file_manager_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ func TestFileManagerService_UpdateOverview(t *testing.T) {
overview := protos.FileOverview(filePath, fileHash)

fakeFileServiceClient := &v1fakes.FakeFileServiceClient{}
fakeFileServiceClient.UpdateOverviewReturns(&mpi.UpdateOverviewResponse{
fakeFileServiceClient.UpdateOverviewReturnsOnCall(0, &mpi.UpdateOverviewResponse{
Overview: overview,
}, nil)

fakeFileServiceClient.UpdateOverviewReturnsOnCall(1, &mpi.UpdateOverviewResponse{}, nil)

fileManagerService := NewFileManagerService(fakeFileServiceClient, types.AgentConfig())
fileManagerService.SetIsConnected(true)

Expand All @@ -51,7 +53,7 @@ func TestFileManagerService_UpdateOverview(t *testing.T) {
})

require.NoError(t, err)
assert.Equal(t, 1, fakeFileServiceClient.UpdateOverviewCallCount())
assert.Equal(t, 2, fakeFileServiceClient.UpdateOverviewCallCount())
}

func TestFileManagerService_UpdateFile(t *testing.T) {
Expand Down

0 comments on commit d239511

Please sign in to comment.