Skip to content

Commit

Permalink
fix(e2e-test): carbon-clickhouse only adds tls certificates for
Browse files Browse the repository at this point in the history
clickhouse with tls configs
  • Loading branch information
lordvidex committed Jul 22, 2023
1 parent e71ea1b commit 5ca3514
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
10 changes: 9 additions & 1 deletion cmd/e2e-test/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Clickhouse struct {
httpAddress string `toml:"-"`
httpsAddress string `toml:"-"`
url string `toml:"-"`
tlsurl string `toml:"-"`
container string `toml:"-"`
client *http.Client
}
Expand Down Expand Up @@ -97,7 +98,7 @@ func (c *Clickhouse) Start() (string, error) {
return "", err
}
port = strings.Split(c.httpsAddress, ":")[1]
c.url = "https://" + c.httpsAddress
c.tlsurl = "https://" + c.httpsAddress
chStart = append(chStart,
"-v", c.Dir+"/server.crt:/etc/clickhouse-server/server.crt",
"-v", c.Dir+"/server.key:/etc/clickhouse-server/server.key",
Expand Down Expand Up @@ -154,6 +155,13 @@ func (c *Clickhouse) URL() string {
return c.url
}

func (c *Clickhouse) TLSURL() (string, bool) {
if c.tlsurl == "" {
return "", false
}
return c.tlsurl, true
}

func (c *Clickhouse) Container() string {
return c.container
}
Expand Down
16 changes: 15 additions & 1 deletion cmd/e2e-test/e2etesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"bytes"
"errors"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -72,6 +73,10 @@ type TestSchema struct {
chVersions map[string]bool `toml:"-"`
}

func (schema *TestSchema) HasTLSSettings() bool {
return strings.Contains(schema.dir, "tls")
}

func getFreeTCPPort(name string) (string, error) {
if len(name) == 0 {
name = "127.0.0.1:0"
Expand Down Expand Up @@ -165,7 +170,16 @@ func testCarbonClickhouse(
cch := CarbonClickhouse{
ConfigTpl: testDir + "/" + test.ConfigTpl,
}
err = cch.Start(clickhouse.URL())
if test.HasTLSSettings() {
url, exists := clickhouse.TLSURL()
if exists {
err = cch.Start(url)
} else {
err = errors.New("test has tls settings but there is no clickhouse tls url")
}
} else {
err = cch.Start(clickhouse.URL())
}
if err != nil {
logger.Error("starting carbon-clickhouse",
zap.String("config", test.name),
Expand Down
2 changes: 1 addition & 1 deletion cmd/e2e-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func main() {
for _, config := range configs {
testDir := config.Test.dir
client := &http.Client{Timeout: time.Minute}
if ch.TLSEnabled {
if ch.TLSEnabled && config.Test.HasTLSSettings() {
conf, err := helpercfg.ParseClientTLSConfig(&helpercfg.TLS{
Certificates: []helpercfg.CertificatePair{{testDir + "/client.key", testDir + "/client.crt"}},
CACertFiles: []string{testDir + "/ca.crt"},
Expand Down

0 comments on commit 5ca3514

Please sign in to comment.