From 812990ce4bc9c9165dbc9b32881049ae51ef5243 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Fri, 15 Dec 2023 22:39:45 +0530 Subject: [PATCH 1/7] added test for newProcessor function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 filesystem/processor_test.go diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go new file mode 100644 index 000000000..80f1a2bb7 --- /dev/null +++ b/filesystem/processor_test.go @@ -0,0 +1,54 @@ +/* + * Copyright IBM Corporation 2021 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package filesystem + + import ( + "testing" + + ) + + func TestNewProcessor(t *testing.T) { + t.Run("test newProcessor", func(t *testing.T) { + // Create a sample options struct + mockOptions := options{ + processFileCallBack: func(sourcecFilePath, destinationFilePath string, config interface{}) (err error) { + return nil + }, + additionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + return nil + }, + deletionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + return nil + }, + mismatchCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + return nil + }, + config: nil, + } + + + processor := newProcessor(mockOptions) + + // Check that the returned processor is not nil + if processor == nil { + t.Error("Expected non-nil processor, but got nil") + } + + // Additional checks specific to your expected behavior can be added here + }) + } + + \ No newline at end of file From 6176e37df12f0134bd3e929b27a22673be94f987 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Fri, 15 Dec 2023 22:43:44 +0530 Subject: [PATCH 2/7] added test for newProcessor function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go index 80f1a2bb7..a8b77c775 100644 --- a/filesystem/processor_test.go +++ b/filesystem/processor_test.go @@ -21,7 +21,7 @@ ) func TestNewProcessor(t *testing.T) { - t.Run("test newProcessor", func(t *testing.T) { + t.Run("checks for a processor instance with given options", func(t *testing.T) { // Create a sample options struct mockOptions := options{ processFileCallBack: func(sourcecFilePath, destinationFilePath string, config interface{}) (err error) { From 193f6f834b29e6ae0d22c027b4d3465c16ed6225 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Mon, 18 Dec 2023 20:39:19 +0530 Subject: [PATCH 3/7] added tests for processFile function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go index a8b77c775..01abd2d97 100644 --- a/filesystem/processor_test.go +++ b/filesystem/processor_test.go @@ -17,6 +17,7 @@ import ( "testing" + "github.com/stretchr/testify/assert" ) @@ -47,8 +48,39 @@ t.Error("Expected non-nil processor, but got nil") } - // Additional checks specific to your expected behavior can be added here + }) } + func TestProcessFile(t *testing.T) { + t.Run("test for the scenario where the processing of a file is successful", func(t *testing.T) { + source := "path/to/source/file.txt" + destination := "path/to/destination/file.txt" + options := options{ + processFileCallBack: func(sourcecFilePath, destinationFilePath string, config interface{}) (err error) { + + return nil + }, + additionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + deletionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + mismatchCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + config: nil, + } + processor := newProcessor(options) + // Invoke the code under test + err := processor.processFile(source, destination) + + // Assert the result + assert.NoError(t, err) + }) +} \ No newline at end of file From a659c37ec3b253ac81f8112580765d2fd1d42ccb Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Mon, 18 Dec 2023 20:45:00 +0530 Subject: [PATCH 4/7] added tests for processFile function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go index 01abd2d97..87aafc444 100644 --- a/filesystem/processor_test.go +++ b/filesystem/processor_test.go @@ -17,7 +17,7 @@ import ( "testing" - "github.com/stretchr/testify/assert" + ) @@ -80,7 +80,9 @@ err := processor.processFile(source, destination) // Assert the result - assert.NoError(t, err) + if err != nil { + t.Errorf("Unexpected error during processing: %v", err) + } }) } \ No newline at end of file From 3329b2c29f6607e410d5fde9f18c418459c3625f Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Tue, 19 Dec 2023 02:51:08 +0530 Subject: [PATCH 5/7] added tests for processDirectory function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 40 +++++++++++++++++++++++ filesystem/testdata/destination/empty.txt | 0 filesystem/testdata/source/empty.txt | 0 3 files changed, 40 insertions(+) create mode 100644 filesystem/testdata/destination/empty.txt create mode 100644 filesystem/testdata/source/empty.txt diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go index 87aafc444..1d76b2771 100644 --- a/filesystem/processor_test.go +++ b/filesystem/processor_test.go @@ -85,4 +85,44 @@ } }) } + +func TestProcessDirectory(t *testing.T) { + + t.Run("test for scenario when a existing source and existing destination directory is processed succesfully ", func(t *testing.T) { + source := "testdata/source" + destination := "testdata/destination" + mockOptions := options{ + processFileCallBack: func(sourcecFilePath, destinationFilePath string, config interface{}) (err error) { + + return nil + }, + additionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + deletionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + mismatchCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + config: nil, + } + + // Call the newProcessor function + processor := newProcessor(mockOptions) + + // Call the code under test + err := processor.processDirectory(source, destination) + + + if err != nil { + t.Errorf("Expected no error, but got: %v", err) + } + }) + +} + \ No newline at end of file diff --git a/filesystem/testdata/destination/empty.txt b/filesystem/testdata/destination/empty.txt new file mode 100644 index 000000000..e69de29bb diff --git a/filesystem/testdata/source/empty.txt b/filesystem/testdata/source/empty.txt new file mode 100644 index 000000000..e69de29bb From 3b6d1cc44cda22686650e658349affa0d1c6d21c Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Tue, 19 Dec 2023 19:27:47 +0530 Subject: [PATCH 6/7] added tests for process function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go index 1d76b2771..62a7a0070 100644 --- a/filesystem/processor_test.go +++ b/filesystem/processor_test.go @@ -125,4 +125,45 @@ func TestProcessDirectory(t *testing.T) { } - \ No newline at end of file + +func TestProcess(t *testing.T) { + t.Run("test for scenario where it succesfully processes existing source and destination directory", func(t *testing.T) { + // Initialize test data + source := "testdata/source/empty.txt" + destination := "testdata/destination" + mockOptions := options{ + processFileCallBack: func(sourcecFilePath, destinationFilePath string, config interface{}) (err error) { + + return nil + }, + additionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + deletionCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + mismatchCallBack: func(sourcePath, destinationPath string, config interface{}) (err error) { + + return nil + }, + config: nil, + } + processor := newProcessor(mockOptions) + + + err := processor.process(source, destination) + + // Check the result + if err != nil { + t.Fatalf("Expected no error, but got: %v", err) + } + + + _, err = os.Lstat(destination) + if err != nil { + t.Fatalf("Expected no error, but got: %v", err) + } + }) +} \ No newline at end of file From 171948cf84ca0527b8c7757476bc10ded3fac1b8 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Tue, 19 Dec 2023 19:37:39 +0530 Subject: [PATCH 7/7] added tests for process function Signed-off-by: satyazzz123 --- filesystem/processor_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/filesystem/processor_test.go b/filesystem/processor_test.go index 62a7a0070..a0503e251 100644 --- a/filesystem/processor_test.go +++ b/filesystem/processor_test.go @@ -17,6 +17,7 @@ import ( "testing" + "os" )