-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
48 lines (38 loc) · 1.15 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func setupMainTest(t *testing.T) (string, error) {
// Create a temporary directory for testing
tempDir, err := os.MkdirTemp("", "test")
if err != nil {
t.Fatalf("Failed to create temporary directory: %v", err)
}
return tempDir, nil
}
func TestMainFunction(t *testing.T) {
// Save command-line arguments
oldArgs := os.Args
tempDir, _ := setupMainTest(t)
defer func() {
// Restore command-line arguments
os.Args = oldArgs
os.RemoveAll(tempDir)
}()
sourceDir := filepath.Join(tempDir, "source")
_ = os.MkdirAll(sourceDir, 0755)
destinationDir := filepath.Join(tempDir, "destination")
// Set up command-line arguments for testing
os.Args = []string{"cmd", "-source=" + sourceDir, "-destination=" + destinationDir}
// Reset flag.CommandLine to clear flags defined in other tests
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
// Call main() function
main()
// TODO: Write more meaningful assertions to verify that the application works at a high level
assert.DirExists(t, sourceDir)
assert.DirExists(t, destinationDir)
}