@@ -21,6 +21,7 @@ import (
2121 "time"
2222
2323 "github.com/nginx/agent/v3/internal/config"
24+ "github.com/nginx/agent/v3/internal/file/filefakes"
2425 "github.com/nginx/agent/v3/internal/model"
2526
2627 "github.com/nginx/agent/v3/pkg/files"
@@ -35,39 +36,6 @@ import (
3536 "github.com/stretchr/testify/require"
3637)
3738
38- type fakeFSO struct {
39- renameSrc , renameDst string
40- renameExternalCalled bool
41- }
42-
43- func (f * fakeFSO ) File (ctx context.Context , file * mpi.File , tempFilePath , expectedHash string ) error {
44- return nil
45- }
46-
47- func (f * fakeFSO ) UpdateOverview (ctx context.Context , instanceID string , filesToUpdate []* mpi.File , configPath string ,
48- iteration int ,
49- ) error {
50- return nil
51- }
52-
53- func (f * fakeFSO ) ChunkedFile (ctx context.Context , file * mpi.File , tempFilePath , expectedHash string ) error {
54- return nil
55- }
56- func (f * fakeFSO ) IsConnected () bool { return true }
57- func (f * fakeFSO ) UpdateFile (ctx context.Context , instanceID string , fileToUpdate * mpi.File ) error {
58- return nil
59- }
60- func (f * fakeFSO ) SetIsConnected (isConnected bool ) {}
61- func (f * fakeFSO ) RenameFile (ctx context.Context , hash , fileName , tempDir string ) error { return nil }
62- func (f * fakeFSO ) RenameExternalFile (ctx context.Context , fileName , tempDir string ) error {
63- f .renameExternalCalled = true
64- f .renameSrc = fileName
65- f .renameDst = tempDir
66-
67- return nil
68- }
69- func (f * fakeFSO ) UpdateClient (ctx context.Context , fileServiceClient mpi.FileServiceClient ) {}
70-
7139func TestFileManagerService_ConfigApply_Add (t * testing.T ) {
7240 ctx := context .Background ()
7341 tempDir := t .TempDir ()
@@ -1438,8 +1406,13 @@ func TestMoveOrDeleteFiles_ExternalFileRenameCalled(t *testing.T) {
14381406 ctx := context .Background ()
14391407 fms := NewFileManagerService (nil , types .AgentConfig (), & sync.RWMutex {})
14401408
1441- fake := & fakeFSO {}
1442- fms .fileServiceOperator = fake
1409+ fakeFSO := & filefakes.FakeFileServiceOperatorInterface {}
1410+
1411+ fakeFSO .RenameExternalFileStub = func (ctx context.Context , fileName , tempDir string ) error {
1412+ return nil
1413+ }
1414+
1415+ fms .fileServiceOperator = fakeFSO
14431416
14441417 fileName := filepath .Join (t .TempDir (), "ext.conf" )
14451418 fms .fileActions = map [string ]* model.FileCache {
@@ -1456,9 +1429,13 @@ func TestMoveOrDeleteFiles_ExternalFileRenameCalled(t *testing.T) {
14561429
14571430 err := fms .moveOrDeleteFiles (ctx , nil )
14581431 require .NoError (t , err )
1459- assert .True (t , fake .renameExternalCalled )
1460- assert .Equal (t , tempPath , fake .renameSrc )
1461- assert .Equal (t , fileName , fake .renameDst )
1432+
1433+ assert .Equal (t , 1 , fakeFSO .RenameExternalFileCallCount (), "RenameExternalFile should be called once" )
1434+
1435+ _ , srcArg , dstArg := fakeFSO .RenameExternalFileArgsForCall (0 )
1436+
1437+ assert .Equal (t , tempPath , srcArg , "RenameExternalFile source argument mismatch" )
1438+ assert .Equal (t , fileName , dstArg , "RenameExternalFile destination argument mismatch" )
14621439}
14631440
14641441func TestDownloadFileContent_MaxBytesLimit (t * testing.T ) {
@@ -1533,7 +1510,7 @@ func TestIsDomainAllowed_EdgeCases(t *testing.T) {
15331510 ok = isDomainAllowed ("http://sub.example.com/path" , []string {"*.example.com" })
15341511 assert .True (t , ok )
15351512
1536- assert .True (t , isWildcardMatch ("example.com" , "*.example.com" ))
1537- assert .True (t , isWildcardMatch ("sub.example.com" , "*.example.com" ))
1538- assert .False (t , isWildcardMatch ("badexample.com" , "*.example.com" ))
1513+ assert .True (t , isMatchesWildcardDomain ("example.com" , "*.example.com" ))
1514+ assert .True (t , isMatchesWildcardDomain ("sub.example.com" , "*.example.com" ))
1515+ assert .False (t , isMatchesWildcardDomain ("badexample.com" , "*.example.com" ))
15391516}
0 commit comments