diff options
| author | Shulhan <ms@kilabit.info> | 2024-02-05 05:26:56 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-02-07 00:33:19 +0700 |
| commit | a390baed9f16c61c9c431691be7bb10151fcde10 (patch) | |
| tree | 3d026a4713acd1dfe1353b7ff39b71ec474da4de /gorankusu_test.go | |
| parent | f2cfe0de0eeec8bc7abf9d754b9e89681743ecff (diff) | |
| download | gorankusu-a390baed9f16c61c9c431691be7bb10151fcde10.tar.xz | |
all: rename the project to gorankusu
The original idea of "trunks" is because the core library that we
use for load testing is named "vegeta" (from Dragon Ball) [1][2], and
Vegeta has a son named Trunks.
In English, trunks also have multiple meanings.
In order to have a unique name, we rename the project to "gorankusu",
which is a combination of "go" (the main programming language
that built the application) and "torankusu" the Hepburn of "Trunks".
[1]: https://github.com/tsenart/vegeta/
[2]: https://en.wikipedia.org/wiki/Vegeta
Implements: https://todo.sr.ht/~shulhan/gorankusu/2
Diffstat (limited to 'gorankusu_test.go')
| -rw-r--r-- | gorankusu_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/gorankusu_test.go b/gorankusu_test.go new file mode 100644 index 0000000..14d0643 --- /dev/null +++ b/gorankusu_test.go @@ -0,0 +1,87 @@ +// SPDX-FileCopyrightText: 2024 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +package gorankusu + +import ( + "crypto/rand" + "log" + "net/http" + "os" + "testing" + "time" + + libhttp "github.com/shuLhan/share/lib/http" + "github.com/shuLhan/share/lib/test/mock" +) + +// dummyHttpd dummy HTTP as target for Gorankusu. +var dummyHttpd *httpdDummy + +// dummyGorankusu the Gorankusu instance that contains [Target] to be tested. +var dummyGorankusu *Gorankusu + +func TestMain(m *testing.M) { + var err error + + // Mock crypto [rand.Reader] for predictable HTTP boundary. + rand.Reader = mock.NewRandReader([]byte(`gorankusu`)) + + dummyHttpd, err = newHttpdDummy() + if err != nil { + log.Fatal(err) + } + defer dummyHttpd.Stop(time.Second) + + var env = Environment{} + + dummyGorankusu, err = New(&env) + if err != nil { + log.Fatal(err) + } + + registerTargetHTTP() + + os.Exit(m.Run()) +} + +func registerTargetHTTP() { + var logp = `registerTargetHTTP` + + var target = &Target{ + ID: `target_http`, + Name: `Target HTTP`, + BaseURL: `http://` + dummyHttpd.Server.Options.Address, + } + var targetHTTPUpload = &HTTPTarget{ + ID: `upload`, + Name: `Upload`, + Method: dummyEndpointUpload.Method, + Path: dummyEndpointUpload.Path, + RequestType: dummyEndpointUpload.RequestType, + Params: KeyFormInput{ + `file`: FormInput{ + Label: `File`, + Kind: FormInputKindFile, + }, + }, + RequestDumper: requestDumperWithoutDate, + ResponseDumper: responseDumperWithoutDate, + } + target.HTTPTargets = append(target.HTTPTargets, targetHTTPUpload) + + var err = dummyGorankusu.RegisterTarget(target) + if err != nil { + log.Fatalf(`%s: %s`, logp, err) + } +} + +func requestDumperWithoutDate(req *http.Request) ([]byte, error) { + req.Header.Del(libhttp.HeaderDate) + return DumpHTTPRequest(req) +} + +func responseDumperWithoutDate(resp *http.Response) ([]byte, error) { + resp.Header.Del(libhttp.HeaderDate) + return DumpHTTPResponse(resp) +} |
