mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
committed by
Cuong Manh Le
parent
35c890048b
commit
71b1b324db
@@ -445,6 +445,8 @@ func initCLI() {
|
|||||||
func writeConfigFile() error {
|
func writeConfigFile() error {
|
||||||
if cfu := v.ConfigFileUsed(); cfu != "" {
|
if cfu := v.ConfigFileUsed(); cfu != "" {
|
||||||
defaultConfigFile = cfu
|
defaultConfigFile = cfu
|
||||||
|
} else if configPath != "" {
|
||||||
|
defaultConfigFile = configPath
|
||||||
}
|
}
|
||||||
f, err := os.OpenFile(defaultConfigFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.FileMode(0o644))
|
f, err := os.OpenFile(defaultConfigFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.FileMode(0o644))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_writeConfigFile(t *testing.T) {
|
||||||
|
tmpdir := t.TempDir()
|
||||||
|
// simulate --config CLI flag by setting configPath manually.
|
||||||
|
configPath = filepath.Join(tmpdir, "ctrld.toml")
|
||||||
|
_, err := os.Stat(configPath)
|
||||||
|
assert.True(t, os.IsNotExist(err))
|
||||||
|
|
||||||
|
assert.NoError(t, writeConfigFile())
|
||||||
|
|
||||||
|
_, err = os.Stat(configPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user