-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a few tests for dispatch init command
- Loading branch information
1 parent
3bc6428
commit 687ac93
Showing
1 changed file
with
63 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,63 @@ | ||
package cli | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInitCommand(t *testing.T) { | ||
t.Run("directoryExists returns false for non-existent directory", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
result, _ := directoryExists("nonexistentdirectory") | ||
assert.False(t, result) | ||
}) | ||
|
||
t.Run("directoryExists returns true for existing directory", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tempDir := t.TempDir() | ||
|
||
result, _ := directoryExists(tempDir) | ||
assert.True(t, result) | ||
}) | ||
|
||
t.Run("directoryExists returns false for file", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tempFile := t.TempDir() + "/tempfile" | ||
_, err := os.Create(tempFile) | ||
assert.Nil(t, err) | ||
|
||
result, _ := directoryExists(tempFile) | ||
assert.False(t, result) | ||
|
||
os.Remove(tempFile) | ||
}) | ||
|
||
t.Run("isDirectoryEmpty returns true for empty directory", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tempDir := t.TempDir() | ||
|
||
result, _ := isDirectoryEmpty(tempDir) | ||
assert.True(t, result) | ||
}) | ||
|
||
t.Run("isDirectoryEmpty returns false for non-empty directory", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
tempDir := t.TempDir() | ||
|
||
tempFile := tempDir + "/tempfile" | ||
_, err := os.Create(tempFile) | ||
assert.Nil(t, err) | ||
|
||
result, _ := isDirectoryEmpty(tempDir) | ||
assert.False(t, result) | ||
|
||
os.Remove(tempFile) | ||
}) | ||
} |