blob: a3ee63dbd51ea4ecb6cccc3d34e3ba3373bec391 [file] [log] [blame]
Copyright 2019 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
package main
import (
fpb ""
var (
serverAddr = flag.String("server_addr", "", "Your http server's address in the format of host:port")
credentialsFile = flag.String("credentials_file", "", "File containing credentials for your server. Leave blank to bypass authentication. File should have exactly one line of the form 'username:password'.")
testSlots = flag.Int("num_test_slots", 10, "Maximum number of slots to test from availability_feed. Slots will be selected randomly")
allFlows = flag.Bool("all_tests", false, "Whether to test all endpoints syncronously, including ListOrders flow.")
healthFlow = flag.Bool("health_check_test", false, "Whether to test the Health endpoint.")
checkFlow = flag.Bool("check_order_test", false, "Whether to test the CheckOrderFulfillability endpoint.")
orderFlow = flag.Bool("create_order_test", false, "Whether to test the CreateOrder endpoint.")
serviceFeed = flag.String("service_feed", "", "Absolute path to service feed required for all tests except health. Feeds can be in either json or pb3 format")
availabilityFeed = flag.String("availability_feed", "", "Absolute path to availability feed required for all tests except health. Feeds can be in either json or pb3 format")
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 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.")
func makeConfig(logger *log.Logger) *utils.Config {
conn, err := api.InitHTTPConnection(*serverAddr, *credentialsFile, *caFile, *fullServerName)
if err != nil {
logger.Fatalf("Failed to init http connection %v", err)
return &utils.Config{Conn: conn,
OrderAllFlows: *allFlows,
OrderHealthFlow: *healthFlow,
OrderCheckFlow: *checkFlow,
OrderOrderFlow: *orderFlow,
func main() {
logger, f, err := utils.MakeLogger(*outputToTerminal, *outputDir)
if err != nil {
log.Fatal("Could not create logger: ", err)
if f != nil {
defer f.Close()
config := makeConfig(logger)
var summary utils.TestSummary
var services []*fpb.Service
var av []*fpb.Availability
if config.OrderAllFlows || config.OrderCheckFlow || config.OrderOrderFlow {
if *availabilityFeed == "" || *serviceFeed == "" {
log.Fatal("please set both availability_feed and service_feed flags")
services, err = utils.ParseServiceFeed(*serviceFeed)
if err != nil {
av, err = utils.AvailabilityFrom(logger, *availabilityFeed, *testSlots, false)
if err != nil {
order.RunTests(context.Background(), logger, config, av, services, &summary)