config_loader_test.go 868 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. t.Parallel()
  10. filename := filepath.Join(t.TempDir(), "server.yml")
  11. contents := `
  12. # Normal options
  13. listen-https: ":10443"
  14. # Note the underscore!
  15. listen_http: ":1080"
  16. # OMG this is allowed now ...
  17. K: /some/file.pem
  18. `
  19. require.Nil(t, os.WriteFile(filename, []byte(contents), 0600))
  20. ctx, err := newYamlSourceFromFile(filename, flagsServe)
  21. require.Nil(t, err)
  22. listenHTTPS, err := ctx.String("listen-https")
  23. require.Nil(t, err)
  24. require.Equal(t, ":10443", listenHTTPS)
  25. listenHTTP, err := ctx.String("listen-http") // No underscore!
  26. require.Nil(t, err)
  27. require.Equal(t, ":1080", listenHTTP)
  28. keyFile, err := ctx.String("key-file") // Long option!
  29. require.Nil(t, err)
  30. require.Equal(t, "/some/file.pem", keyFile)
  31. }