generated from replicatedhq/krew-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |