Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm
package wasm
import (
"gitlab.com/elixxir/client/v4/bindings"
"reflect"
"testing"
)
// Tests that the map representing DMClient returned by newDMClientJS contains
// all of the methods on DMClient.
func Test_newDMClientJS(t *testing.T) {
dmcType := reflect.TypeOf(&DMClient{})
dmc := newDMClientJS(&bindings.DMClient{})
if len(dmc) != dmcType.NumMethod() {
t.Errorf("DMClient JS object does not have all methods."+
"\nexpected: %d\nreceived: %d", dmcType.NumMethod(), len(dmc))
}
for i := 0; i < dmcType.NumMethod(); i++ {
method := dmcType.Method(i)
if _, exists := dmc[method.Name]; !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
// Tests that DMClient has all the methods that
// [bindings.DMClient] has.
func Test_DMClientMethods(t *testing.T) {
dmcType := reflect.TypeOf(&DMClient{})
binDmcType := reflect.TypeOf(&bindings.DMClient{})
var numOfExcludedFields int
if _, exists := dmcType.MethodByName("GetDatabaseName"); !exists {
t.Errorf("GetDatabaseName was not found.")
} else {
numOfExcludedFields++
}
nm := dmcType.NumMethod() - numOfExcludedFields
if binDmcType.NumMethod() != nm {
t.Errorf("WASM DMClient object does not have all methods from "+
"bindings.\nexpected: %d\nreceived: %d", binDmcType.NumMethod(), nm)
}
for i := 0; i < binDmcType.NumMethod(); i++ {
method := binDmcType.Method(i)
if _, exists := dmcType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}