-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconfig_test.go
More file actions
58 lines (47 loc) · 1.57 KB
/
config_test.go
File metadata and controls
58 lines (47 loc) · 1.57 KB
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
49
50
51
52
53
54
55
56
57
58
package integration_test
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestConfigFileCreatedOnStartup(t *testing.T) {
tmpHome := t.TempDir()
var configDir string
var env []string
switch runtime.GOOS {
case "darwin":
configDir = filepath.Join(tmpHome, "Library", "Application Support", "lstk")
env = append(os.Environ(), "HOME="+tmpHome)
case "linux":
configDir = filepath.Join(tmpHome, ".config", "lstk")
env = append(os.Environ(), "HOME="+tmpHome, "XDG_CONFIG_HOME=")
case "windows":
configDir = filepath.Join(tmpHome, "AppData", "Roaming", "lstk")
env = append(os.Environ(), "APPDATA="+filepath.Join(tmpHome, "AppData", "Roaming"))
default:
t.Skipf("unsupported OS: %s", runtime.GOOS)
}
configFile := filepath.Join(configDir, "config.toml")
cmd := exec.Command(binaryPath(), "start")
cmd.Env = env
err := cmd.Start()
require.NoError(t, err, "failed to start lstk")
defer cmd.Process.Kill()
// Poll for config file creation - check every 50ms, timeout after 2s
require.Eventually(t, func() bool {
_, err := os.Stat(configFile)
return err == nil
}, 2*time.Second, 20*time.Millisecond, "config.toml should be created")
assert.DirExists(t, configDir, "config directory should be created at OS-specific location")
content, err := os.ReadFile(configFile)
require.NoError(t, err)
configStr := string(content)
assert.Contains(t, configStr, `type = 'aws'`)
assert.Contains(t, configStr, `tag = 'latest'`)
assert.Contains(t, configStr, `port = '4566'`)
}