diff options
| author | Shulhan <ms@kilabit.info> | 2024-04-18 00:33:01 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-04-18 00:41:07 +0700 |
| commit | 1a6d02199e0d44024648c5e805f8f10d7fc4b30a (patch) | |
| tree | 34918af7ac3bcf2777ba2d9744f801a2243edb86 /client_test.go | |
| parent | a28f1684d9b427149f7a8f03f865bdf57eafc08e (diff) | |
| download | kamusku-1a6d02199e0d44024648c5e805f8f10d7fc4b30a.tar.xz | |
all: remove unused Client and activeClient
Since we now only have one client, apiClient, rename it to Client so it
can be used by other module or package later.
Diffstat (limited to 'client_test.go')
| -rw-r--r-- | client_test.go | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go new file mode 100644 index 0000000..aaf6ed3 --- /dev/null +++ b/client_test.go @@ -0,0 +1,110 @@ +// SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info> +// SPDX-License-Identifier: GPL-3.0-or-later + +package kamusku + +import ( + "testing" + + "git.sr.ht/~shulhan/kbbi" + "git.sr.ht/~shulhan/pakakeh.go/lib/test" +) + +func TestApiClient_Lookup_offline(t *testing.T) { + testServer.offline = true + + client := NewClient(testServerAPI) + + cases := []struct { + desc string + words []string + exp kbbi.LookupResponse + expError string + }{{ + desc: `With empty input`, + }, { + desc: `With words not found`, + words: []string{`a`}, + }, { + desc: `With valid word in cache`, + words: []string{`mengeja`}, + exp: kbbi.LookupResponse{ + `mengeja`: testKataMengeja, + }, + }, { + desc: `With duplicate words`, + words: []string{`mengeja`, `mengeja`}, + exp: kbbi.LookupResponse{ + `mengeja`: testKataMengeja, + }, + }} + + for _, c := range cases { + t.Logf(c.desc) + + got, err := client.Lookup(c.words) + if err != nil { + test.Assert(t, `error`, c.expError, err.Error()) + continue + } + + test.Assert(t, `kbbi.LookupResponse`, c.exp, got) + } +} + +func TestApiClient_Lookup_online(t *testing.T) { + t.Skip() + + testServer.offline = false + + client := NewClient(testServerAPI) + + cases := []struct { + desc string + words []string + exp kbbi.LookupResponse + expError string + }{{ + desc: `With empty input`, + }, { + desc: `With valid word in cache`, + words: []string{`mengeja`}, + exp: kbbi.LookupResponse{ + `mengeja`: testKataMengeja, + }, + }, { + desc: `With duplicate words`, + words: []string{`mengeja`, `mengeja`}, + exp: kbbi.LookupResponse{ + `mengeja`: testKataMengeja, + }, + }, { + desc: `With one of the word not in cache`, + words: []string{`mengeja`, `eja`}, + exp: kbbi.LookupResponse{ + `mengeja`: testKataMengeja, + `eja`: &kbbi.Word{ + Definition: []*kbbi.WordDefinition{{ + Value: `lafal huruf satu demi satu`, + Classes: []string{`Verba: kata kerja`}, + }}, + }, + }, + }} + + for _, c := range cases { + t.Logf(c.desc) + + got, err := client.Lookup(c.words) + if err != nil { + test.Assert(t, `error`, c.expError, err.Error()) + continue + } + + for k, v := range got { + t.Logf(`got: %s = %+v`, k, v) + } + + test.Assert(t, `LookupResponse`, c.exp, got) + } +} |
