config_loader_test.go 854 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package cmd
  2. import (
  3. "github.com/stretchr/testify/require"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. )
  8. func TestNewYamlSourceFromFile(t *testing.T) {
  9. filename := filepath.Join(t.TempDir(), "server.yml")
  10. contents := `
  11. # Normal options
  12. listen-https: ":10443"
  13. # Note the underscore!
  14. listen_http: ":1080"
  15. # OMG this is allowed now ...
  16. K: /some/file.pem
  17. `
  18. require.Nil(t, os.WriteFile(filename, []byte(contents), 0600))
  19. ctx, err := newYamlSourceFromFile(filename, flagsServe)
  20. require.Nil(t, err)
  21. listenHTTPS, err := ctx.String("listen-https")
  22. require.Nil(t, err)
  23. require.Equal(t, ":10443", listenHTTPS)
  24. listenHTTP, err := ctx.String("listen-http") // No underscore!
  25. require.Nil(t, err)
  26. require.Equal(t, ":1080", listenHTTP)
  27. keyFile, err := ctx.String("key-file") // Long option!
  28. require.Nil(t, err)
  29. require.Equal(t, "/some/file.pem", keyFile)
  30. }