test: add dovecot integration test (#11996)
This commit is contained in:
parent
b3fdc39c53
commit
39e4bcdc90
|
|
@ -3,15 +3,19 @@ package dovecot
|
|||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/textproto"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
)
|
||||
|
||||
func TestDovecotIntegration(t *testing.T) {
|
||||
|
|
@ -158,3 +162,49 @@ const sampleIP = `ip reset_timestamp last_update num_logins num_cmds num_connect
|
|||
|
||||
const sampleUser = `user reset_timestamp last_update num_logins num_cmds user_cpu sys_cpu clock_time min_faults maj_faults vol_cs invol_cs disk_input disk_output read_count read_bytes write_count write_bytes mail_lookup_path mail_lookup_attr mail_read_count mail_read_bytes mail_cache_hits
|
||||
user.1@domain.test 1453969886 1454603963.039864 7503897 52595715 100831175.372000 83849071.112000 4326001931528183.495762 763950011 1112443 4120386897 3685239306 41679480946688 1819070669176832 2368906465 2957928122981169 3545389615 1666822498251286 24396105 302845 20155768 669946617705 1557255080`
|
||||
|
||||
func TestDovecotContainerIntegration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping dovecot integration tests.")
|
||||
}
|
||||
|
||||
testdata, err := filepath.Abs("testdata/dovecot.conf")
|
||||
require.NoError(t, err, "determining absolute path of test-data failed")
|
||||
|
||||
servicePort := "24242"
|
||||
container := testutil.Container{
|
||||
Image: "dovecot/dovecot",
|
||||
ExposedPorts: []string{servicePort},
|
||||
BindMounts: map[string]string{
|
||||
"/etc/dovecot/dovecot.conf": testdata,
|
||||
},
|
||||
WaitingFor: wait.ForAll(
|
||||
wait.ForLog("starting up for imap"),
|
||||
wait.ForListeningPort(nat.Port(servicePort)),
|
||||
),
|
||||
}
|
||||
defer func() {
|
||||
require.NoError(t, container.Terminate(), "terminating container failed")
|
||||
}()
|
||||
|
||||
err = container.Start()
|
||||
require.NoError(t, err, "failed to start container")
|
||||
|
||||
d := &Dovecot{Servers: []string{
|
||||
fmt.Sprintf("%s:%s", container.Address, container.Ports[servicePort]),
|
||||
}, Type: "global"}
|
||||
|
||||
var acc testutil.Accumulator
|
||||
require.NoError(t, d.Gather(&acc))
|
||||
require.Eventually(t,
|
||||
func() bool { return acc.HasMeasurement("dovecot") },
|
||||
5*time.Second,
|
||||
10*time.Millisecond,
|
||||
)
|
||||
|
||||
require.True(t, acc.HasTag("dovecot", "type"))
|
||||
require.True(t, acc.HasField("dovecot", "sys_cpu"))
|
||||
require.True(t, acc.HasField("dovecot", "write_count"))
|
||||
require.True(t, acc.HasField("dovecot", "mail_read_count"))
|
||||
require.True(t, acc.HasField("dovecot", "auth_failures"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
## This is a default dovecot.conf file with the
|
||||
## addition of the service stats section
|
||||
|
||||
mail_home=/srv/mail/%Lu
|
||||
mail_location=sdbox:~/Mail
|
||||
mail_uid=1000
|
||||
mail_gid=1000
|
||||
|
||||
protocols = imap pop3 submission sieve lmtp
|
||||
|
||||
first_valid_uid = 1000
|
||||
last_valid_uid = 1000
|
||||
|
||||
passdb {
|
||||
driver = static
|
||||
args = password=pass
|
||||
}
|
||||
|
||||
ssl=yes
|
||||
ssl_cert=<cert.pem
|
||||
ssl_key=<key.pem
|
||||
|
||||
namespace {
|
||||
inbox = yes
|
||||
separator = /
|
||||
}
|
||||
|
||||
service lmtp {
|
||||
inet_listener {
|
||||
port = 24
|
||||
}
|
||||
}
|
||||
|
||||
plugin {
|
||||
old_stats_refresh = 30 secs
|
||||
}
|
||||
|
||||
service old-stats {
|
||||
inet_listener {
|
||||
address = *
|
||||
port = 24242
|
||||
}
|
||||
}
|
||||
|
||||
listen = *
|
||||
|
||||
log_path=/dev/stdout
|
||||
info_log_path=/dev/stdout
|
||||
debug_log_path=/dev/stdout
|
||||
Loading…
Reference in New Issue