Skip to content

Commit

Permalink
Sarthak | Adds few more validations in main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
SarthakMakhija committed Aug 19, 2023
1 parent f32a9c1 commit e414eee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
1. Integrate blast.go in main
5. Validate the options in main
8. Incorporate request timeout

6. Run against a sample server
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Options:
-c Number of workers to run concurrently. Total number of requests cannot
be smaller than the concurrency level. Default is 50.
-f Payload file path.
-p External executable process path. The external process should print the payload
-p External executable process path. The external process must print the payload
on stdout. Load generation payload can be either specified through -f or -p.
-rps Rate limit in requests per second (RPS) per worker. Default is no rate limit.
-z Duration of blast to send requests. When duration is reached,
Expand All @@ -54,7 +54,7 @@ Options:
-Rsr Read successful responses is the successful responses to read from the target server.
The load generation will stop if either the duration (-z) has exceeded or
the total successful responses have been read. Either of "-Rtr"
or "-Rsr" should be specified. This flag is applied only if
or "-Rsr" must be specified, if -Rr is set. This flag is applied only if
"Read responses" (-Rr) is true.
-conn Number of connections to open with the target URL.
Expand Down Expand Up @@ -120,6 +120,9 @@ func assertFileAndProcessPath(filePath string, processPath string) {
if len(strings.Trim(filePath, " ")) == 0 && len(strings.Trim(processPath, " ")) == 0 {
exitFunction("both -f and -p cannot be blank.")
}
if len(strings.Trim(filePath, " ")) != 0 && len(strings.Trim(processPath, " ")) != 0 {
exitFunction("both -f and -p cannot be specified.")
}
}

func assertRequestTimeout(timeout int) {
Expand Down Expand Up @@ -179,6 +182,9 @@ func assertResponseReading(
if readTotalResponses > 0 && readSuccessfulResponses > 0 {
exitFunction("both -Rtr and -Rsr cannot be specified.")
}
if readTotalResponses == 0 && readSuccessfulResponses == 0 {
exitFunction("either of -Rtr or -Rsr must be specified.")
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func TestRunBlastWithEmptyFileAndProcessPath(t *testing.T) {
})
}

func TestRunBlastWithNonEmptyFilePathAndNonEmptyProcessPath(t *testing.T) {
exitFunction = exitWithPanic
assert.Panics(t, func() {
assertFileAndProcessPath("./filePayload", "./exe")
})
}

func TestRunBlastWithEmptyFileAndNonEmptyProcessPath(t *testing.T) {
exitFunction = exitWithPanic
assert.NotPanics(t, func() {
Expand Down

0 comments on commit e414eee

Please sign in to comment.