mirror of
https://github.com/slackhq/nebula.git
synced 2026-05-16 04:47:38 +02:00
Some checks failed
smoke-extra / Run windows smoke test (push) Waiting to run
Build and test / Build and test on macos-latest (push) Waiting to run
Build and test / Build and test on windows-latest (push) Waiting to run
gofmt / Run gofmt (push) Successful in 11s
smoke-extra / freebsd-amd64 (push) Failing after 13s
smoke-extra / linux-amd64-ipv6disable (push) Failing after 12s
smoke-extra / netbsd-amd64 (push) Failing after 14s
smoke-extra / openbsd-amd64 (push) Failing after 12s
smoke-extra / linux-386 (push) Failing after 12s
smoke / Run multi node smoke test (push) Failing after 1m27s
Build and test / Build all and test on ubuntu-linux (push) Failing after 20m14s
Build and test / Build and test on linux with boringcrypto (push) Failing after 5m14s
Build and test / Build and test on linux with pkcs11 (push) Failing after 3m12s
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDefaultPathInDir(t *testing.T) {
|
|
t.Run("prefers config.yaml when both exist", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
want := filepath.Join(dir, "config.yaml")
|
|
other := filepath.Join(dir, "config.yml")
|
|
require.NoError(t, os.WriteFile(want, []byte("a: 1"), 0644))
|
|
require.NoError(t, os.WriteFile(other, []byte("a: 2"), 0644))
|
|
|
|
got, err := defaultPathInDir(dir)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, want, got)
|
|
})
|
|
|
|
t.Run("returns config.yaml when only it exists", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
want := filepath.Join(dir, "config.yaml")
|
|
require.NoError(t, os.WriteFile(want, []byte("a: 1"), 0644))
|
|
|
|
got, err := defaultPathInDir(dir)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, want, got)
|
|
})
|
|
|
|
t.Run("falls back to config.yml when only it exists", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
want := filepath.Join(dir, "config.yml")
|
|
require.NoError(t, os.WriteFile(want, []byte("a: 1"), 0644))
|
|
|
|
got, err := defaultPathInDir(dir)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, want, got)
|
|
})
|
|
|
|
t.Run("errors when neither exists and names both paths", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
got, err := defaultPathInDir(dir)
|
|
assert.Empty(t, got)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), filepath.Join(dir, "config.yaml"))
|
|
assert.Contains(t, err.Error(), filepath.Join(dir, "config.yml"))
|
|
})
|
|
}
|
|
|
|
func TestDefaultPath(t *testing.T) {
|
|
got, err := DefaultPath()
|
|
if err != nil {
|
|
ex, exErr := os.Executable()
|
|
require.NoError(t, exErr)
|
|
assert.Contains(t, err.Error(), filepath.Dir(ex))
|
|
return
|
|
}
|
|
ex, err := os.Executable()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, filepath.Dir(ex), filepath.Dir(got))
|
|
assert.Contains(t, []string{"config.yaml", "config.yml"}, filepath.Base(got))
|
|
}
|