mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-20 09:06:45 +00:00
GODT-1205: "RCPT TO" does not contain all addressed from "CC"
This commit is contained in:
committed by
Jakub Cuth
parent
91dcb2f773
commit
22d2bcc21d
@ -19,10 +19,8 @@ package fakeapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
"github.com/nsf/jsondiff"
|
||||
)
|
||||
|
||||
type method string
|
||||
@ -34,12 +32,6 @@ const (
|
||||
DELETE method = "DELETE"
|
||||
)
|
||||
|
||||
type fakeCall struct {
|
||||
method method
|
||||
path string
|
||||
request []byte
|
||||
}
|
||||
|
||||
func (ctl *Controller) checkAndRecordCall(method method, path string, req interface{}) error {
|
||||
ctl.lock.Lock()
|
||||
defer ctl.lock.Unlock()
|
||||
@ -54,11 +46,7 @@ func (ctl *Controller) checkAndRecordCall(method method, path string, req interf
|
||||
}
|
||||
}
|
||||
|
||||
ctl.calls = append(ctl.calls, &fakeCall{
|
||||
method: method,
|
||||
path: path,
|
||||
request: request,
|
||||
})
|
||||
ctl.calls.Register(string(method), path, request)
|
||||
|
||||
if ctl.noInternetConnection {
|
||||
return pmapi.ErrNoConnection
|
||||
@ -68,38 +56,17 @@ func (ctl *Controller) checkAndRecordCall(method method, path string, req interf
|
||||
}
|
||||
|
||||
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 string(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 string(call.method) == method && call.path == path {
|
||||
requests = append(requests, call.request)
|
||||
}
|
||||
}
|
||||
return requests
|
||||
return ctl.calls.GetCalls(method, path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user