options_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package main
  2. import (
  3. "path/filepath"
  4. "testing"
  5. "github.com/docker/docker/daemon/config"
  6. "github.com/spf13/pflag"
  7. "gotest.tools/v3/assert"
  8. is "gotest.tools/v3/assert/cmp"
  9. )
  10. func TestCommonOptionsInstallFlags(t *testing.T) {
  11. flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
  12. opts := newDaemonOptions(&config.Config{})
  13. opts.installFlags(flags)
  14. err := flags.Parse([]string{
  15. "--tlscacert=/foo/cafile",
  16. "--tlscert=/foo/cert",
  17. "--tlskey=/foo/key",
  18. })
  19. assert.Check(t, err)
  20. assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile))
  21. assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile))
  22. assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key"))
  23. }
  24. func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
  25. flags := pflag.NewFlagSet("testing", pflag.ContinueOnError)
  26. opts := newDaemonOptions(&config.Config{})
  27. opts.installFlags(flags)
  28. err := flags.Parse([]string{})
  29. assert.Check(t, err)
  30. assert.Check(t, is.Equal(filepath.Join(defaultCertPath(), "ca.pem"), opts.TLSOptions.CAFile))
  31. assert.Check(t, is.Equal(filepath.Join(defaultCertPath(), "cert.pem"), opts.TLSOptions.CertFile))
  32. assert.Check(t, is.Equal(filepath.Join(defaultCertPath(), "key.pem"), opts.TLSOptions.KeyFile))
  33. }