From d24e63345f1d9aa4eece38c19482145cfadc39b4 Mon Sep 17 00:00:00 2001 From: Bartosz Fenski Date: Sat, 29 Jun 2024 08:30:08 +0200 Subject: [PATCH] first test --- pkg/plugin/mount_test.go | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 pkg/plugin/mount_test.go diff --git a/pkg/plugin/mount_test.go b/pkg/plugin/mount_test.go new file mode 100644 index 0000000..0e44f48 --- /dev/null +++ b/pkg/plugin/mount_test.go @@ -0,0 +1,51 @@ +package plugin + +import ( + "os" + "testing" +) + +func TestValidateMountPoint(t *testing.T) { + t.Run("Mount point exists", func(t *testing.T) { + // Create a temporary directory to simulate an existing mount point + tempDir := t.TempDir() + + // Call the function + err := validateMountPoint(tempDir) + + // Check the result + if err != nil { + t.Errorf("validateMountPoint(%s) returned an unexpected error: %v", tempDir, err) + } + }) + + t.Run("Mount point does not exist", func(t *testing.T) { + // Define a path that does not exist + nonExistentPath := "/path/that/does/not/exist" + + // Call the function + err := validateMountPoint(nonExistentPath) + + // Check the result + if err == nil { + t.Errorf("validateMountPoint(%s) should have returned an error, but it did not", nonExistentPath) + } + }) +} + +func TestValidateMountPoint_FileInsteadOfDirectory(t *testing.T) { + // Create a temporary file to simulate a file instead of a directory + tempFile, err := os.CreateTemp("", "testfile") + if err != nil { + t.Fatalf("Failed to create temporary file: %v", err) + } + defer os.Remove(tempFile.Name()) + + // Call the function + err = validateMountPoint(tempFile.Name()) + + // Check the result + if err != nil { + t.Errorf("validateMountPoint(%s) returned an unexpected error: %v", tempFile.Name(), err) + } +}