diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-27 23:03:47 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-27 23:07:18 -0400 |
commit | 73f58c1e901082441b0ce9497b35cd9d80bd7f7d (patch) | |
tree | 176673cd5ccbd0d87c3b8305eac6753a0f40285e | |
parent | c6ced3e74b52df4ed8a63868f86e095058c41100 (diff) | |
download | getwtxt-73f58c1e901082441b0ce9497b35cd9d80bd7f7d.tar.gz |
test/bench parseQueryOut()
-rw-r--r-- | query_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/query_test.go b/query_test.go new file mode 100644 index 0000000..835ba90 --- /dev/null +++ b/query_test.go @@ -0,0 +1,87 @@ +package main + +import ( + "net" + "reflect" + "strings" + "testing" + + "github.com/getwtxt/registry" +) + +func Test_parseQueryOut(t *testing.T) { + initTestConf() + + urls := "https://gbmor.dev/twtxt.txt" + nick := "gbmor" + + out, _, err := registry.GetTwtxt(urls) + if err != nil { + t.Errorf("Couldn't set up test: %v\n", err) + } + + statusmap, err := registry.ParseUserTwtxt(out, nick, urls) + if err != nil { + t.Errorf("Couldn't set up test: %v\n", err) + } + + err = twtxtCache.AddUser(nick, urls, net.ParseIP("127.0.0.1"), statusmap) + if err != nil { + t.Errorf("Couldn't set up test: %v\n", err) + } + + t.Run("Parsing Status Query", func(t *testing.T) { + data, err := twtxtCache.QueryAllStatuses() + if err != nil { + t.Errorf("%v\n", err) + } + + out := parseQueryOut(data) + + conv := strings.Split(string(out), "\n") + + // It likes to append an empty element to the end. + // I need to fix that in the library. + if len(conv) > 0 && conv[len(conv)-1] == "" { + conv = conv[:len(conv)-1] + } + + if !reflect.DeepEqual(data, conv) { + t.Errorf("Pre- and Post- parseQueryOut data are inequal:\n%#v\n%#v\n", data, conv) + } + }) +} + +func Benchmark_parseQueryOut(b *testing.B) { + initTestConf() + + urls := "https://gbmor.dev/twtxt.txt" + nick := "gbmor" + + out, _, err := registry.GetTwtxt(urls) + if err != nil { + b.Errorf("Couldn't set up test: %v\n", err) + } + + statusmap, err := registry.ParseUserTwtxt(out, nick, urls) + if err != nil { + b.Errorf("Couldn't set up test: %v\n", err) + } + + err = twtxtCache.AddUser(nick, urls, net.ParseIP("127.0.0.1"), statusmap) + if err != nil { + b.Errorf("Couldn't set up test: %v\n", err) + } + + data, err := twtxtCache.QueryAllStatuses() + if err != nil { + b.Errorf("%v\n", err) + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + parseQueryOut(data) + } + +} |