Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions config-template.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
# cli_commands are used to specify what the cli commands should be.
server: false # true/false should we be running in server mode?
iterations: 5 # The number of times we wish to itterate over the workload
concurrency: 1 # The nuber of users we want to simulate running the iterations
silent: false # true/false do we want to output command line information
output: "csv.test" # name of the .csv file we should be writting too
interval: 0 # how long we should wait before each workload is ran
stop: 0 # the total time we want to be runnins workload intervalse
workload: "cf:push" # A single iteration workload that will be executed in the order commands are provided
# This file has all the command line parameters you can provide (listed alphabetical order) and their default values.
# You could modify the values here conveniently and run the command as follows:
# pat -config=config-template.yml
#
app: "assets/dora" # filepath to app, defaults to provided dora in assets
app:manifest: "" # filepath to cf manifest for the app
concurrency: 1 # number of workers to execute the workload in parallel, can be static or ramping up, i.e. 1..3
concurrency:timeBetweenSteps: 60 # seconds between adding additonal workers when ramping works up
csv-dir: "output/csvs" # Directory to Store CSVs
interval: 0 # repeat a workload every n seconds, to be used with -stop
iterations: 1 # number of pushes to attempt
list-workloads: "false" # Lists the available workloads
logging:file: "" # A file to log to, or empty to log to STDOUT. By default it creates a file with name GUID in csv-dir folder.
logging:level: "INFO" # The level to log at, one of all, debug2, debug1, debug, info, warn, error, fatal, off
redis-host: "localhost" # Redis hostname
redis-password: "" # Redis password
redis-port: 6379 # Redis port
rest:space: "" # space to target for REST api
rest:target: "" # the target for the REST api
rest:username: "" # username for REST api
server: false # true to run the HTTP server interface
silent: false # true to run silently and exit without interaction when finished
stop: 0 # repeat a repeating interval until n seconds, to be used with -interval
use-redis-store: false # True if redis should be used (requires the -redis-host, -redis-port and -redis-password arguments)
use-redis-worker: false # Runs in master mode, sending work to perform to a redis queue
workload: "cf:push" # a comma-separated list of operations a user should issue. use 'pat -list-workloads' to see available workload options.
#

23 changes: 19 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"
"io/ioutil"
"os"

"fmt"
"launchpad.net/goyaml"
)

Expand Down Expand Up @@ -68,15 +68,15 @@ func (f *f) allowDoubleSetting(target interface{}, name string, fn func()) {

func (f *f) Parse(args []string) error {
config := f.flagSet.String("config", "", "YML file containing configuration parameters")

if err := f.ParseEnv(); err != nil {
return err
}

f.flagSet.Parse(args)

if len(*config) > 0 {
if err := f.ParseConfig(*config); err != nil {
return err
return err
}
}

Expand All @@ -102,19 +102,34 @@ func (f *f) ParseConfig(path string) error {
}

yml := make(map[string]string)

err = goyaml.Unmarshal(file, &yml)
if err != nil {
return err
}

f.flagSet.Visit(func(flag *flag.Flag) {
delete(yml, flag.Name)

})


var invalid_string string

for k, v := range yml {
flag := f.flagSet.Lookup(k)

// if wrong parameters are passed, do not crash, exit with message.
if flag != nil {
flag.Value.Set(v)
}
} else {
invalid_string = invalid_string + "," + k
}
}

if len(invalid_string) > 0 {
return fmt.Errorf("invalid strings passed %s", invalid_string)
}

return nil
}
22 changes: 21 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,25 @@ var _ = Describe("ConfigAndFlags", func() {
Ω(err.Error()).Should(ContainSubstring("YAML error"))
os.RemoveAll(tempfile)
})
})

It("Returns an error when passed a wrong parameter ", func() {
tempfile := filepath.Join(os.TempDir(), "test.yml")
configFile, err := os.Create(tempfile)
if err != nil {
Ω(err).ShouldNot(HaveOccurred())
}

configFile.WriteString("WrongStringPassed: 1\n")
configFile.Sync()
configFile.Close()
flags = []string{"-config", tempfile}

err = config.Parse(flags)
Ω(err).Should(HaveOccurred())
Ω(err.Error()).To(Equal("invalid strings passed ,WrongStringPassed"))
os.RemoveAll(tempfile)
})

})
})