Skip to content

Commit

Permalink
a few tests for dispatch init command
Browse files Browse the repository at this point in the history
  • Loading branch information
chicoxyzzy committed Jun 26, 2024
1 parent 3bc6428 commit 687ac93
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions cli/init_test.go
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)
})
}

0 comments on commit 687ac93

Please sign in to comment.