From 5b830377ea24a2a07bd2ee02ee412f6f4ab63362 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Sun, 10 Dec 2023 01:17:45 +0530 Subject: [PATCH 1/4] test : add tests for mergeDeletionCallBack Signed-off-by: satyazzz123 --- filesystem/merger_test.go | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 filesystem/merger_test.go diff --git a/filesystem/merger_test.go b/filesystem/merger_test.go new file mode 100644 index 000000000..fcb193f90 --- /dev/null +++ b/filesystem/merger_test.go @@ -0,0 +1,72 @@ +// package filesystem + +// import ( +// "os" +// "testing" +// ) + +// func TestMergeDeletionCallBack(t *testing.T) { +// t.Run("test for source file and destination directory", func(t *testing.T) { +// source := "/move2kube/to/nonexistent/source" +// destination := "/move2kube/to/destination" +// config := interface{}(nil) + +// // Call the merge function +// err := mergeDeletionCallBack(source, destination, config) + +// // Assert that the error is not nil (as the source file does not exist) +// if err == nil { +// t.Fatalf("Expected non-nil error, but got nil") +// } + +// // Check if the error is due to the source file not existing +// if !os.IsNotExist(err) { +// t.Fatalf("Expected source file to not exist, but got error: %v", err) +// } + +// // Additional checks based on the expected behavior after fixing the source path +// // For example, check the state of the destination directory or other behavior +// _, destErr := os.Stat(destination) +// if destErr == nil { +// t.Error("Expected destination directory not to exist, but it exists") +// } + +// // Additional checks specific to your expected behavior can be added here +// }) +// } +package filesystem + +import ( + "os" + "testing" +) + +func TestMergeDeletionCallBack(t *testing.T) { + t.Run(" test for scenario when function is called with a non-existent source file and an existing destination directory", func(t *testing.T) { + source := "/move2kube/nonexistent/source" + destination := "/move2kube/destination" + config := interface{}(nil) + + // Call the merge function + err := mergeDeletionCallBack(source, destination, config) + + // Assert that the error is not nil (as the source file does not exist) + if err == nil { + t.Fatalf("Expected non-nil error, but got nil") + } + + // Check if the error is due to the source file not existing + if !os.IsNotExist(err) { + t.Fatalf("Expected source file to not exist, but got error: %v", err) + } + + // Additional checks based on the expected behavior after fixing the source path + // For example, check the state of the destination directory or other behavior + _, destErr := os.Stat(destination) + if !os.IsNotExist(destErr) { + t.Error("Expected destination directory not to exist, but it exists") + } + + // Additional checks specific to your expected behavior can be added here + }) +} From 28cc7c27f85d2b7ce219bd4ff7a31624524a6503 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Sun, 10 Dec 2023 01:19:14 +0530 Subject: [PATCH 2/4] test : add tests for mergeDeletionCallBack Signed-off-by: satyazzz123 --- filesystem/merger_test.go | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/filesystem/merger_test.go b/filesystem/merger_test.go index fcb193f90..ce65ed978 100644 --- a/filesystem/merger_test.go +++ b/filesystem/merger_test.go @@ -1,39 +1,4 @@ -// package filesystem -// import ( -// "os" -// "testing" -// ) - -// func TestMergeDeletionCallBack(t *testing.T) { -// t.Run("test for source file and destination directory", func(t *testing.T) { -// source := "/move2kube/to/nonexistent/source" -// destination := "/move2kube/to/destination" -// config := interface{}(nil) - -// // Call the merge function -// err := mergeDeletionCallBack(source, destination, config) - -// // Assert that the error is not nil (as the source file does not exist) -// if err == nil { -// t.Fatalf("Expected non-nil error, but got nil") -// } - -// // Check if the error is due to the source file not existing -// if !os.IsNotExist(err) { -// t.Fatalf("Expected source file to not exist, but got error: %v", err) -// } - -// // Additional checks based on the expected behavior after fixing the source path -// // For example, check the state of the destination directory or other behavior -// _, destErr := os.Stat(destination) -// if destErr == nil { -// t.Error("Expected destination directory not to exist, but it exists") -// } - -// // Additional checks specific to your expected behavior can be added here -// }) -// } package filesystem import ( From 07ac0a7f634538bab3d0c31ebf19b11305ff9495 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Sun, 10 Dec 2023 01:21:23 +0530 Subject: [PATCH 3/4] test : add tests for mergeDeletionCallBack Signed-off-by: satyazzz123 --- filesystem/merger_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/filesystem/merger_test.go b/filesystem/merger_test.go index ce65ed978..bce4082ba 100644 --- a/filesystem/merger_test.go +++ b/filesystem/merger_test.go @@ -25,13 +25,12 @@ func TestMergeDeletionCallBack(t *testing.T) { t.Fatalf("Expected source file to not exist, but got error: %v", err) } - // Additional checks based on the expected behavior after fixing the source path - // For example, check the state of the destination directory or other behavior + _, destErr := os.Stat(destination) if !os.IsNotExist(destErr) { t.Error("Expected destination directory not to exist, but it exists") } - // Additional checks specific to your expected behavior can be added here + }) } From 9acf886fff9ffc61ed0cd1266d465b6476598526 Mon Sep 17 00:00:00 2001 From: satyazzz123 Date: Sun, 10 Dec 2023 21:35:09 +0530 Subject: [PATCH 4/4] added license to file Signed-off-by: satyazzz123 --- filesystem/merger_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/filesystem/merger_test.go b/filesystem/merger_test.go index bce4082ba..4fca04845 100644 --- a/filesystem/merger_test.go +++ b/filesystem/merger_test.go @@ -1,4 +1,18 @@ - +/* + * 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 (