Bug fixes
1. Modify and cancel booking requests to match what is sent in reality (eg no merhant_id, service_id, etc)
2. Consider ListBookingsSuccess in cancel booking flow
3. Exit status matches status of tests (totalErrors)
diff --git a/api/api.go b/api/api.go
index 0ae2130..1c7caea 100644
--- a/api/api.go
+++ b/api/api.go
@@ -289,7 +289,7 @@
gB := Bookings(resp.GetBookings())
if len(gB) != len(tB) {
- return out, fmt.Errorf("number of bookings differ, ListBookings invalid. Got: %d, Want: %d. Abandoning all bookings from this flow", len(gB), len(tB))
+ return nil, fmt.Errorf("number of bookings differ, ListBookings invalid. Got: %d, Want: %d. Abandoning all bookings from this flow", len(gB), len(tB))
}
sort.Sort(gB)
@@ -332,10 +332,12 @@
}
// CancelBooking is a clean up method that cancels all supplied bookings.
-func CancelBooking(b *mpb.Booking, conn *HTTPConnection) error {
- b.Status = mpb.BookingStatus_CANCELED
+func CancelBooking(bookingID string, conn *HTTPConnection) error {
reqPB := &mpb.UpdateBookingRequest{
- Booking: b,
+ Booking: &mpb.Booking{
+ BookingId: bookingID,
+ Status: mpb.BookingStatus_CANCELED,
+ },
}
req, err := conn.marshaler.MarshalToString(reqPB)
if err != nil {
@@ -376,15 +378,18 @@
if err != nil {
return fmt.Errorf("could not complete booking, abandoning rescheduling flow: %v", err)
}
- slot := newBooking.GetSlot()
// New slot.
lastAvailability := slots[len(slots)-1]
- slot.StartSec = lastAvailability.GetStartSec()
- slot.DurationSec = lastAvailability.GetDurationSec()
reqPB := &mpb.UpdateBookingRequest{
- Booking: newBooking,
+ Booking: &mpb.Booking{
+ BookingId: newBooking.GetBookingId(),
+ Slot: &mpb.Slot{
+ StartSec: lastAvailability.GetStartSec(),
+ DurationSec: lastAvailability.GetDurationSec(),
+ },
+ },
}
req, err := conn.marshaler.MarshalToString(reqPB)
if err != nil {
@@ -399,7 +404,7 @@
if iE := utils.ValidateBooking(resp.GetBooking(), newBooking); iE != nil {
return fmt.Errorf("invalid response. UpdateBooking: %s, abandoning slot 1/1", iE.Error())
}
- return CancelBooking(resp.GetBooking(), conn)
+ return CancelBooking(resp.GetBooking().GetBookingId(), conn)
}
// CheckOrderFulfillability attempts to send a CheckOrderFulfillabilityRequest
diff --git a/testclient/bookingClient.go b/testclient/bookingClient.go
index c85de5f..e77546c 100644
--- a/testclient/bookingClient.go
+++ b/testclient/bookingClient.go
@@ -48,6 +48,7 @@
outputDir = flag.String("output_dir", "", "Absolute path of dir to dump log file.")
caFile = flag.String("ca_file", "", "Absolute path to your server's Certificate Authority root cert. Downloading all roots currently recommended by the Google Internet Authority is a suitable alternative https://pki.google.com/roots.pem. Leave blank to connect using http rather than https.")
fullServerName = flag.String("full_server_name", "", "Fully qualified domain name. Same name used to sign CN. Only necessary if ca_file is specified and the base URL differs from the server address.")
+ outputToTerminal = flag.Bool("output_to_terminal", false, "Output to terminal rather than a file.")
)
type counters struct {
@@ -129,7 +130,7 @@
totalErrors += stats.CreateBookingErrors
log.Printf("CreateBooking Errors: %d/%d", stats.CreateBookingErrors, stats.CreateBookingErrors+stats.CreateBookingSuccess)
}
- if *listFlow || *allFlows {
+ if *listFlow || *allFlows || *cancelAllBookings {
if stats.ListBookingsSuccess {
log.Println("ListBookings Succeeded")
} else {
@@ -158,20 +159,22 @@
}
log.Println("\n************* End Stats *************\n")
- os.Exit(0)
+ os.Exit(totalErrors)
}
func main() {
flag.Parse()
var stats counters
- // Set up logging before continuing with flows
- f, err := createLogFile()
- if err != nil {
- log.Fatalf("Failed to create log file %v", err)
+ if !*outputToTerminal {
+ // Set up logging before continuing with flows
+ f, err := createLogFile()
+ if err != nil {
+ log.Fatalf("Failed to create log file %v", err)
+ }
+ defer f.Close()
+ log.SetOutput(f)
}
- defer f.Close()
- log.SetOutput(f)
conn, err := api.InitHTTPConnection(*serverAddr, *credentialsFile, *caFile, *fullServerName)
if err != nil {
@@ -287,7 +290,7 @@
if len(b) > 0 {
utils.LogFlow("Cancel Booking", "Start")
for i, booking := range b {
- if err = api.CancelBooking(booking, conn); err != nil {
+ if err = api.CancelBooking(booking.GetBookingId(), conn); err != nil {
log.Printf("%s. abandoning booking %d/%d", err.Error(), i, len(b))
stats.CancelBookingsErrors++
continue
diff --git a/testclient/orderClient.go b/testclient/orderClient.go
index 02125eb..718ff23 100644
--- a/testclient/orderClient.go
+++ b/testclient/orderClient.go
@@ -44,6 +44,7 @@
outputDir = flag.String("output_dir", "", "Absolute path of dir to dump log file.")
caFile = flag.String("ca_file", "", "Absolute path to your server's Certificate Authority root cert. Downloading all roots currently recommended by the Google Internet Authority is a suitable alternative https://pki.google.com/roots.pem. Leave blank to connect using http rather than https.")
fullServerName = flag.String("full_server_name", "", "Fully qualified domain name. Same name used to sign CN. Only necessary if ca_file is specified and the base URL differs from the server address.")
+ outputToTerminal = flag.Bool("output_to_terminal", false, "Output to terminal rather than a file.")
)
type counters struct {
@@ -112,20 +113,22 @@
}
log.Println("\n************* End Stats *************\n")
- os.Exit(0)
+ os.Exit(totalErrors)
}
func main() {
flag.Parse()
var stats counters
- // Set up logging before continuing with flows
- f, err := createLogFile()
- if err != nil {
- log.Fatalf("Failed to create log file %v", err)
+ if !*outputToTerminal {
+ // Set up logging before continuing with flows
+ f, err := createLogFile()
+ if err != nil {
+ log.Fatalf("Failed to create log file %v", err)
+ }
+ defer f.Close()
+ log.SetOutput(f)
}
- defer f.Close()
- log.SetOutput(f)
conn, err := api.InitHTTPConnection(*serverAddr, *credentialsFile, *caFile, *fullServerName)
if err != nil {