mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
dovecot: Include cli-based tests in the coverage tests
Many areas of the dovecot library are tested via chamuyero scripts, but these were not being included in the coverage report. This patch extends the dovecot-auth-cli tests so that they are now coverage-aware.
This commit is contained in:
1
cmd/dovecot-auth-cli/.gitignore
vendored
1
cmd/dovecot-auth-cli/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
*.log
|
||||
dovecot-auth-cli
|
||||
dovecot-auth-cli.test
|
||||
|
||||
33
cmd/dovecot-auth-cli/coverage_test.go
Normal file
33
cmd/dovecot-auth-cli/coverage_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// This package is tested externally (see test.sh).
|
||||
// However, we need this to do coverage tests.
|
||||
//
|
||||
// See coverage_test.go for the details, this is the same horrible hack.
|
||||
//
|
||||
// +build coveragebin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRunMain(t *testing.T) {
|
||||
done := make(chan bool)
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
go func() {
|
||||
<-signals
|
||||
done <- true
|
||||
}()
|
||||
signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
main()
|
||||
done <- true
|
||||
}()
|
||||
|
||||
<-done
|
||||
}
|
||||
7
cmd/dovecot-auth-cli/coverage_wrapper
Executable file
7
cmd/dovecot-auth-cli/coverage_wrapper
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Wrapper for dovecot-auth-cli to run when we build it in coverage mode.
|
||||
|
||||
exec ./dovecot-auth-cli.test -test.run ^TestRunMain$ \
|
||||
-test.coverprofile="$COVER_DIR/test-`date +%s.%N`.out" \
|
||||
"$@"
|
||||
@@ -6,26 +6,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/dovecot"
|
||||
)
|
||||
|
||||
func main() {
|
||||
a := dovecot.NewAuth(os.Args[1]+"-userdb", os.Args[1]+"-client")
|
||||
flag.Parse()
|
||||
a := dovecot.NewAuth(flag.Arg(0)+"-userdb", flag.Arg(0)+"-client")
|
||||
|
||||
var ok bool
|
||||
var err error
|
||||
|
||||
switch os.Args[2] {
|
||||
switch flag.Arg(1) {
|
||||
case "exists":
|
||||
ok, err = a.Exists(os.Args[3])
|
||||
ok, err = a.Exists(flag.Arg(2))
|
||||
case "auth":
|
||||
ok, err = a.Authenticate(os.Args[3], os.Args[4])
|
||||
ok, err = a.Authenticate(flag.Arg(2), flag.Arg(3))
|
||||
default:
|
||||
fmt.Printf("unknown subcommand\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if ok {
|
||||
@@ -34,5 +34,4 @@ func main() {
|
||||
}
|
||||
|
||||
fmt.Printf("no: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,13 @@ init
|
||||
# Build the binary once, so we can use it and launch it in chamuyero scripts.
|
||||
# Otherwise, we not only spend time rebuilding it over and over, but also "go
|
||||
# run" masks the exit code, which is something we care about.
|
||||
go build dovecot-auth-cli.go
|
||||
if [ "${COVER_DIR}" != "" ]; then
|
||||
go test -covermode=count -coverpkg=../../... -c \
|
||||
$GOFLAGS -tags="coveragebin $GOTAGS"
|
||||
cp coverage_wrapper dovecot-auth-cli
|
||||
else
|
||||
go build $GOFLAGS -tags="$GOTAGS" dovecot-auth-cli.go
|
||||
fi
|
||||
|
||||
for i in *.cmy; do
|
||||
if ! chamuyero $i > $i.log 2>&1 ; then
|
||||
@@ -19,3 +25,4 @@ for i in *.cmy; do
|
||||
done
|
||||
|
||||
success
|
||||
exit 0
|
||||
|
||||
@@ -18,4 +18,4 @@ client <- AUTH 1 PLAIN service=smtp secured no-penalty nologin resp=dXNlcm5hbWUA
|
||||
client -> OTHER
|
||||
|
||||
c <~ no: invalid response
|
||||
c wait 1
|
||||
c wait 0
|
||||
|
||||
@@ -18,4 +18,4 @@ client <- AUTH 1 PLAIN service=smtp secured no-penalty nologin resp=dXNlcm5hbWUA
|
||||
client -> FAIL 1
|
||||
|
||||
c <- no: <nil>
|
||||
c wait 1
|
||||
c wait 0
|
||||
|
||||
@@ -11,6 +11,5 @@ userdb <- USER 1 username service=smtp
|
||||
|
||||
userdb -> NOTFOUND 1
|
||||
|
||||
c wait 1
|
||||
|
||||
c <- no: <nil>
|
||||
c wait 0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
c = ./dovecot-auth-cli .missingsocket exists username
|
||||
c <~ no: dial unix .missingsocket-userdb
|
||||
c wait 1
|
||||
c wait 0
|
||||
|
||||
c = ./dovecot-auth-cli .missingsocket auth username password
|
||||
c <~ no: dial unix .missingsocket-client
|
||||
c wait 1
|
||||
c wait 0
|
||||
|
||||
Reference in New Issue
Block a user