GODT-1205: "RCPT TO" does not contain all addressed from "CC"

This commit is contained in:
Alexander Bilyak
2021-09-06 21:13:37 +00:00
committed by Jakub Cuth
parent 91dcb2f773
commit 22d2bcc21d
11 changed files with 236 additions and 91 deletions

View File

@ -17,62 +17,25 @@
package liveapi
import (
"fmt"
"github.com/nsf/jsondiff"
)
type fakeCall struct {
method string
path string
request []byte
}
func (ctl *Controller) recordCall(method, path string, request []byte) {
ctl.lock.Lock()
defer ctl.lock.Unlock()
ctl.calls = append(ctl.calls, &fakeCall{
method: method,
path: path,
request: request,
})
ctl.calls.Register(method, path, request)
}
func (ctl *Controller) PrintCalls() {
fmt.Println("API calls:")
for idx, call := range ctl.calls {
fmt.Printf("%02d: [%s] %s\n", idx+1, call.method, call.path)
if call.request != nil && string(call.request) != "null" {
fmt.Printf("\t%s\n", call.request)
}
}
ctl.calls.PrintCalls()
}
func (ctl *Controller) WasCalled(method, path string, expectedRequest []byte) bool {
for _, call := range ctl.calls {
if call.method != method || call.path != path {
continue
}
if string(expectedRequest) == "" {
return true
}
diff, _ := jsondiff.Compare(call.request, expectedRequest, &jsondiff.Options{})
isSuperset := diff == jsondiff.FullMatch || diff == jsondiff.SupersetMatch
if isSuperset {
return true
}
}
return false
return ctl.calls.WasCalled(method, path, expectedRequest)
}
func (ctl *Controller) WasCalledRegex(methodRegex, pathRegex string, expectedRequest []byte) (bool, error) {
return ctl.calls.WasCalledRegex(methodRegex, pathRegex, expectedRequest)
}
func (ctl *Controller) GetCalls(method, path string) [][]byte {
requests := [][]byte{}
for _, call := range ctl.calls {
if call.method == method && call.path == path {
requests = append(requests, call.request)
}
}
return requests
return ctl.calls.GetCalls(method, path)
}

View File

@ -22,6 +22,7 @@ import (
"sync"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/ProtonMail/proton-bridge/test/context/calls"
"github.com/sirupsen/logrus"
)
@ -30,7 +31,7 @@ type Controller struct {
log *logrus.Entry
// Internal states.
lock *sync.RWMutex
calls []*fakeCall
calls calls.Calls
messageIDsByUsername map[string][]string
// State controlled by test.
@ -41,7 +42,7 @@ func NewController(_ string) (*Controller, pmapi.Manager) {
controller := &Controller{
log: logrus.WithField("pkg", "live-controller"),
lock: &sync.RWMutex{},
calls: []*fakeCall{},
calls: calls.Calls{},
messageIDsByUsername: map[string][]string{},
noInternetConnection: false,