daemon/job: test that sample configs are buildable

This commit is contained in:
Christian Schwarz 2020-07-19 23:59:33 +02:00
parent 4e702eedc9
commit 95fc299733
4 changed files with 54 additions and 0 deletions

View File

@ -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)
})
}
}

View File

@ -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")

View File

@ -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")

View File

@ -0,0 +1,10 @@
package tls
import "testing"
var fakeCertificateLoading bool
func FakeCertificateLoading(t *testing.T) {
t.Logf("faking certificate loading")
fakeCertificateLoading = true
}