mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-16 15:16:44 +00:00
test(GODT-2746): polish the test code.
This commit is contained in:
@ -28,6 +28,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Masterminds/semver/v3"
|
"github.com/Masterminds/semver/v3"
|
||||||
|
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/events"
|
"github.com/ProtonMail/proton-bridge/v3/internal/events"
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||||
"github.com/cucumber/godog"
|
"github.com/cucumber/godog"
|
||||||
@ -153,36 +154,7 @@ func (s *scenario) theUserSetSMTPModeToSSL() error {
|
|||||||
return s.t.bridge.SetSMTPSSL(context.Background(), true)
|
return s.t.bridge.SetSMTPSSL(context.Background(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scenario) theUserReportsABug() error {
|
type testBugReport struct {
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", "email", "client", false)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *scenario) theUserReportsABugWithSingleHeaderChange(key, value string) error {
|
|
||||||
switch keyValue := key; keyValue {
|
|
||||||
case "osType":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), value, "osVersion", "title", "description", "username", "email", "client", false)
|
|
||||||
case "osVersion":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", value, "title", "description", "username", "email", "client", false)
|
|
||||||
case "Title":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", value, "description", "username", "email", "client", false)
|
|
||||||
case "Description":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", value, "username", "email", "client", false)
|
|
||||||
case "Username":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", value, "email", "client", false)
|
|
||||||
case "Email":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", value, "client", false)
|
|
||||||
case "Client":
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", "email", value, false)
|
|
||||||
case "Attachment":
|
|
||||||
att, _ := strconv.ParseBool(value)
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), "osType", "osVersion", "title", "description", "username", "email", "client", att)
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("Wrong header (\"%s\") is being checked", key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *scenario) theUserReportsABugWithDetails(value *godog.DocString) error {
|
|
||||||
type BugReportTest struct {
|
|
||||||
OSType string `json:"OS"`
|
OSType string `json:"OS"`
|
||||||
OSVersion string `json:"OSVersion"`
|
OSVersion string `json:"OSVersion"`
|
||||||
Title string `json:"Title"`
|
Title string `json:"Title"`
|
||||||
@ -191,18 +163,70 @@ func (s *scenario) theUserReportsABugWithDetails(value *godog.DocString) error {
|
|||||||
Email string `json:"Email"`
|
Email string `json:"Email"`
|
||||||
Client string `json:"Client"`
|
Client string `json:"Client"`
|
||||||
Attachment bool `json:"Attachment"`
|
Attachment bool `json:"Attachment"`
|
||||||
|
|
||||||
|
bridge *bridge.Bridge
|
||||||
}
|
}
|
||||||
|
|
||||||
bugReport := BugReportTest{OSType: "osType", OSVersion: "osVersion", Title: "title", Description: "description", Username: "username", Email: "email", Client: "client", Attachment: false}
|
func newTestBugReport(bridge *bridge.Bridge) *testBugReport {
|
||||||
|
return &testBugReport{
|
||||||
|
OSType: "osType",
|
||||||
|
OSVersion: "osVersion",
|
||||||
|
Title: "title",
|
||||||
|
Description: "description",
|
||||||
|
Username: "username",
|
||||||
|
Email: "email",
|
||||||
|
Client: "client",
|
||||||
|
Attachment: false,
|
||||||
|
bridge: bridge,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
jsonString := value
|
func (r *testBugReport) report() error {
|
||||||
|
return r.bridge.ReportBug(context.Background(), r.OSType, r.OSVersion, r.Title, r.Description, r.Username, r.Email, r.Client, r.Attachment)
|
||||||
|
}
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(jsonString.Content), &bugReport)
|
func (s *scenario) theUserReportsABug() error {
|
||||||
|
return newTestBugReport(s.t.bridge).report()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scenario) theUserReportsABugWithSingleHeaderChange(key, value string) error {
|
||||||
|
bugReport := newTestBugReport(s.t.bridge)
|
||||||
|
|
||||||
|
switch key {
|
||||||
|
case "osType":
|
||||||
|
bugReport.OSType = value
|
||||||
|
case "osVersion":
|
||||||
|
bugReport.OSVersion = value
|
||||||
|
case "Title":
|
||||||
|
bugReport.Title = value
|
||||||
|
case "Description":
|
||||||
|
bugReport.Description = value
|
||||||
|
case "Username":
|
||||||
|
bugReport.Username = value
|
||||||
|
case "Email":
|
||||||
|
bugReport.Email = value
|
||||||
|
case "Client":
|
||||||
|
bugReport.Client = value
|
||||||
|
case "Attachment":
|
||||||
|
att, err := strconv.ParseBool(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
return fmt.Errorf("failed to parse bug report attachment preferences: %w", err)
|
||||||
|
}
|
||||||
|
bugReport.Attachment = att
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Wrong header (\"%s\") is being checked", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.t.bridge.ReportBug(context.Background(), bugReport.OSType, bugReport.OSVersion, bugReport.Title, bugReport.Description, bugReport.Username, bugReport.Email, bugReport.Client, bugReport.Attachment)
|
return bugReport.report()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scenario) theUserReportsABugWithDetails(value *godog.DocString) error {
|
||||||
|
bugReport := newTestBugReport(s.t.bridge)
|
||||||
|
if err := json.Unmarshal([]byte(value.Content), &bugReport); err != nil {
|
||||||
|
return fmt.Errorf("cannot parse bug report details: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return bugReport.report()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scenario) bridgeSendsAConnectionUpEvent() error {
|
func (s *scenario) bridgeSendsAConnectionUpEvent() error {
|
||||||
|
|||||||
@ -83,8 +83,8 @@ func (s *scenario) theHeaderInTheRequestToHasSetTo(method, path, key, value stri
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if haveKey := call.RequestHeader.Get(key); haveKey != value {
|
if haveValue := call.RequestHeader.Get(key); haveValue != value {
|
||||||
return fmt.Errorf("have header %q, want %q", haveKey, value)
|
return fmt.Errorf("header field %q have %q, want %q", key, haveValue, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -124,8 +124,8 @@ func (s *scenario) theHeaderInTheMultipartRequestToHasSetTo(method, path, key, v
|
|||||||
return fmt.Errorf("failed to parse multipart form: %w", err)
|
return fmt.Errorf("failed to parse multipart form: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if haveKey := req.FormValue(key); haveKey != value {
|
if haveValue := req.FormValue(key); haveValue != value {
|
||||||
return fmt.Errorf("have header %q, want %q", haveKey, value)
|
return fmt.Errorf("header field %q have %q, want %q", key, haveValue, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user