From 95fc299733c0833ba2d12d023586fa0fb1cb69c8 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 19 Jul 2020 23:59:33 +0200 Subject: [PATCH] daemon/job: test that sample configs are buildable --- daemon/job/build_jobs_test.go | 36 ++++++++++++++++++++++++++++++++ transport/tls/connect_tls.go | 4 ++++ transport/tls/serve_tls.go | 4 ++++ transport/tls/tls_test_helper.go | 10 +++++++++ 4 files changed, 54 insertions(+) create mode 100644 transport/tls/tls_test_helper.go diff --git a/daemon/job/build_jobs_test.go b/daemon/job/build_jobs_test.go index 6be2efc..6fca84f 100644 --- a/daemon/job/build_jobs_test.go +++ b/daemon/job/build_jobs_test.go @@ -2,12 +2,16 @@ package job import ( "fmt" + "path" + "path/filepath" "testing" + "github.com/kr/pretty" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/zrepl/zrepl/config" + "github.com/zrepl/zrepl/transport/tls" ) func TestValidateReceivingSidesDoNotOverlap(t *testing.T) { @@ -108,3 +112,35 @@ jobs: } } + +func TestSampleConfigsAreBuiltWithoutErrors(t *testing.T) { + paths, err := filepath.Glob("../../config/samples/*") + if err != nil { + t.Errorf("glob failed: %+v", err) + } + + for _, p := range paths { + + if path.Ext(p) != ".yml" { + t.Logf("skipping file %s", p) + continue + } + + t.Run(p, func(t *testing.T) { + c, err := config.ParseConfig(p) + if err != nil { + t.Errorf("error parsing %s:\n%+v", p, err) + } + + t.Logf("file: %s", p) + t.Log(pretty.Sprint(c)) + + tls.FakeCertificateLoading(t) + jobs, err := JobsFromConfig(c) + t.Logf("jobs: %#v", jobs) + assert.NoError(t, err) + }) + + } + +} diff --git a/transport/tls/connect_tls.go b/transport/tls/connect_tls.go index ebe447f..4fc76f9 100644 --- a/transport/tls/connect_tls.go +++ b/transport/tls/connect_tls.go @@ -23,6 +23,10 @@ func TLSConnecterFromConfig(in *config.TLSConnect) (*TLSConnecter, error) { Timeout: in.DialTimeout, } + if fakeCertificateLoading { + return &TLSConnecter{in.Address, dialer, nil}, nil + } + ca, err := tlsconf.ParseCAFile(in.Ca) if err != nil { return nil, errors.Wrap(err, "cannot parse ca file") diff --git a/transport/tls/serve_tls.go b/transport/tls/serve_tls.go index c4c0e2f..dd156cc 100644 --- a/transport/tls/serve_tls.go +++ b/transport/tls/serve_tls.go @@ -25,6 +25,10 @@ func TLSListenerFactoryFromConfig(c *config.Global, in *config.TLSServe) (transp return nil, errors.New("fields 'ca', 'cert' and 'key'must be specified") } + if fakeCertificateLoading { + return func() (transport.AuthenticatedListener, error) { return nil, nil }, nil + } + clientCA, err := tlsconf.ParseCAFile(in.Ca) if err != nil { return nil, errors.Wrap(err, "cannot parse ca file") diff --git a/transport/tls/tls_test_helper.go b/transport/tls/tls_test_helper.go new file mode 100644 index 0000000..c778425 --- /dev/null +++ b/transport/tls/tls_test_helper.go @@ -0,0 +1,10 @@ +package tls + +import "testing" + +var fakeCertificateLoading bool + +func FakeCertificateLoading(t *testing.T) { + t.Logf("faking certificate loading") + fakeCertificateLoading = true +}