diff options
| author | Shulhan <ms@kilabit.info> | 2024-03-17 18:07:32 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-03-18 21:55:35 +0700 |
| commit | a37fef27aa5411b7df102cb227768fe8a010ea42 (patch) | |
| tree | df6e528c5c4f859017c704422b1cdee19bf141ac /http_log_test.go | |
| parent | b86893f6dd315cb253ec5479501791c500d82876 (diff) | |
| download | haminer-a37fef27aa5411b7df102cb227768fe8a010ea42.tar.xz | |
all: add unit test for ParseUDPPacket
The function signature to parse the UDP packet changes to return HTTPLog
instead of as receiver.
Diffstat (limited to 'http_log_test.go')
| -rw-r--r-- | http_log_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/http_log_test.go b/http_log_test.go new file mode 100644 index 0000000..157ff71 --- /dev/null +++ b/http_log_test.go @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +package haminer + +import ( + "encoding/json" + "testing" + + "git.sr.ht/~shulhan/pakakeh.go/lib/test" +) + +func TestParseUDPPacket(t *testing.T) { + var ( + logp = `TestParseUDPPacket` + tdata *test.Data + err error + ) + tdata, err = test.LoadData(`testdata/ParseUDPPacket_test.txt`) + if err != nil { + t.Fatal(logp, err) + } + + var listCase = []string{ + `http_log_0000`, + } + + var ( + httpLog *HTTPLog + tag string + exp string + got []byte + ) + for _, tag = range listCase { + httpLog = ParseUDPPacket(tdata.Input[tag], nil) + + got, err = json.MarshalIndent(httpLog, ``, ` `) + if err != nil { + t.Fatal(logp, err) + } + + exp = string(tdata.Output[tag]) + test.Assert(t, tag, exp, string(got)) + } +} |
