Skip to content
Snippets Groups Projects
Commit 84ec5c21 authored by Jono Wenger's avatar Jono Wenger
Browse files

Add tests that check that wasm objects have the same methods as their bindings counterparts

parent d15828e8
No related branches found
No related tags found
1 merge request!6XX-4050 / Send E2E test
...@@ -35,3 +35,24 @@ func Test_newAuthenticatedConnectionJS(t *testing.T) { ...@@ -35,3 +35,24 @@ func Test_newAuthenticatedConnectionJS(t *testing.T) {
} }
} }
} }
// Tests that AuthenticatedConnection has all the methods that
// [bindings.AuthenticatedConnection] has.
func Test_AuthenticatedConnectionMethods(t *testing.T) {
authType := reflect.TypeOf(&AuthenticatedConnection{})
binAuthType := reflect.TypeOf(&bindings.AuthenticatedConnection{})
if binAuthType.NumMethod() != authType.NumMethod() {
t.Errorf("WASM AuthenticatedConnection object does not have all "+
"methods from bindings.\nexpected: %d\nreceived: %d",
binAuthType.NumMethod(), authType.NumMethod())
}
for i := 0; i < binAuthType.NumMethod(); i++ {
method := binAuthType.Method(i)
if _, exists := authType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -32,3 +32,23 @@ func Test_newBackupJS(t *testing.T) { ...@@ -32,3 +32,23 @@ func Test_newBackupJS(t *testing.T) {
} }
} }
} }
// Tests that Backup has all the methods that [bindings.Backup] has.
func Test_BackupMethods(t *testing.T) {
backupType := reflect.TypeOf(&Backup{})
binBackupType := reflect.TypeOf(&bindings.Backup{})
if binBackupType.NumMethod() != backupType.NumMethod() {
t.Errorf("WASM Backup object does not have all methods from bindings."+
"\nexpected: %d\nreceived: %d",
binBackupType.NumMethod(), backupType.NumMethod())
}
for i := 0; i < binBackupType.NumMethod(); i++ {
method := binBackupType.Method(i)
if _, exists := backupType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -34,3 +34,23 @@ func Test_newChannelJS(t *testing.T) { ...@@ -34,3 +34,23 @@ func Test_newChannelJS(t *testing.T) {
} }
} }
} }
// Tests that Channel has all the methods that [bindings.Channel] has.
func Test_ChannelMethods(t *testing.T) {
chanType := reflect.TypeOf(&Channel{})
binChanType := reflect.TypeOf(&bindings.Channel{})
if binChanType.NumMethod() != chanType.NumMethod() {
t.Errorf("WASM Channel object does not have all methods from bindings."+
"\nexpected: %d\nreceived: %d",
binChanType.NumMethod(), chanType.NumMethod())
}
for i := 0; i < binChanType.NumMethod(); i++ {
method := binChanType.Method(i)
if _, exists := chanType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -35,3 +35,23 @@ func Test_newCmixJS(t *testing.T) { ...@@ -35,3 +35,23 @@ func Test_newCmixJS(t *testing.T) {
} }
} }
} }
// Tests that Cmix has all the methods that [bindings.Cmix] has.
func Test_CmixMethods(t *testing.T) {
cmixType := reflect.TypeOf(&Cmix{})
binCmixType := reflect.TypeOf(&bindings.Cmix{})
if binCmixType.NumMethod() != cmixType.NumMethod() {
t.Errorf("WASM Cmix object does not have all methods from bindings."+
"\nexpected: %d\nreceived: %d",
binCmixType.NumMethod(), cmixType.NumMethod())
}
for i := 0; i < binCmixType.NumMethod(); i++ {
method := binCmixType.Method(i)
if _, exists := cmixType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -32,3 +32,23 @@ func Test_newConnectJS(t *testing.T) { ...@@ -32,3 +32,23 @@ func Test_newConnectJS(t *testing.T) {
} }
} }
} }
// Tests that Connection has all the methods that [bindings.Connection] has.
func Test_ConnectionMethods(t *testing.T) {
connType := reflect.TypeOf(&Connection{})
binConnType := reflect.TypeOf(&bindings.Connection{})
if binConnType.NumMethod() != connType.NumMethod() {
t.Errorf("WASM Connection object does not have all methods from "+
"bindings.\nexpected: %d\nreceived: %d",
binConnType.NumMethod(), connType.NumMethod())
}
for i := 0; i < binConnType.NumMethod(); i++ {
method := binConnType.Method(i)
if _, exists := connType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -34,3 +34,23 @@ func Test_newE2eJS(t *testing.T) { ...@@ -34,3 +34,23 @@ func Test_newE2eJS(t *testing.T) {
} }
} }
} }
// Tests that E2e has all the methods that [bindings.E2e] has.
func Test_E2eMethods(t *testing.T) {
e2eType := reflect.TypeOf(&E2e{})
binE2eType := reflect.TypeOf(&bindings.E2e{})
if binE2eType.NumMethod() != e2eType.NumMethod() {
t.Errorf("WASM E2e object does not have all methods from bindings."+
"\nexpected: %d\nreceived: %d",
binE2eType.NumMethod(), e2eType.NumMethod())
}
for i := 0; i < binE2eType.NumMethod(); i++ {
method := binE2eType.Method(i)
if _, exists := e2eType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -33,6 +33,26 @@ func Test_newFileTransferJS(t *testing.T) { ...@@ -33,6 +33,26 @@ func Test_newFileTransferJS(t *testing.T) {
} }
} }
// Tests that FileTransfer has all the methods that [bindings.FileTransfer] has.
func Test_FileTransferMethods(t *testing.T) {
ftType := reflect.TypeOf(&FileTransfer{})
binFtType := reflect.TypeOf(&bindings.FileTransfer{})
if binFtType.NumMethod() != ftType.NumMethod() {
t.Errorf("WASM FileTransfer object does not have all methods from "+
"bindings.\nexpected: %d\nreceived: %d",
binFtType.NumMethod(), ftType.NumMethod())
}
for i := 0; i < binFtType.NumMethod(); i++ {
method := binFtType.Method(i)
if _, exists := ftType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
// Tests that the map representing FilePartTracker returned by // Tests that the map representing FilePartTracker returned by
// newFilePartTrackerJS contains all of the methods on FilePartTracker. // newFilePartTrackerJS contains all of the methods on FilePartTracker.
func Test_newFilePartTrackerJS(t *testing.T) { func Test_newFilePartTrackerJS(t *testing.T) {
...@@ -52,3 +72,24 @@ func Test_newFilePartTrackerJS(t *testing.T) { ...@@ -52,3 +72,24 @@ func Test_newFilePartTrackerJS(t *testing.T) {
} }
} }
} }
// Tests that FilePartTracker has all the methods that
// [bindings.FilePartTracker] has.
func Test_FilePartTrackerMethods(t *testing.T) {
fptType := reflect.TypeOf(&FilePartTracker{})
binFptType := reflect.TypeOf(&bindings.FilePartTracker{})
if binFptType.NumMethod() != fptType.NumMethod() {
t.Errorf("WASM FilePartTracker object does not have all methods from "+
"bindings.\nexpected: %d\nreceived: %d",
binFptType.NumMethod(), fptType.NumMethod())
}
for i := 0; i < binFptType.NumMethod(); i++ {
method := binFptType.Method(i)
if _, exists := fptType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -191,8 +191,32 @@ func (ce *clientError) Report(source, message, trace string) { ...@@ -191,8 +191,32 @@ func (ce *clientError) Report(source, message, trace string) {
// //
// Parameters: // Parameters:
// - args[0] - Javascript object that has functions that implement the // - args[0] - Javascript object that has functions that implement the
// [bindings.ClientError] interface // [bindings.ClientError] interface.
func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) interface{} { func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) interface{} {
c.api.RegisterClientErrorCallback(&clientError{utils.WrapCB(args[0], "Report")}) c.api.RegisterClientErrorCallback(&clientError{utils.WrapCB(args[0], "Report")})
return nil return nil
} }
// trackServicesCallback adheres to the [bindings.TrackServicesCallback]
// interface.
type trackServicesCallback struct {
callback func(args ...interface{}) js.Value
}
func (tsc *trackServicesCallback) Callback(marshalData []byte, err error) {
tsc.callback(utils.CopyBytesToJS(marshalData), utils.JsTrace(err))
}
// TrackServices will return, via a callback, the list of services that the
// backend keeps track of, which is formally referred to as a
// [message.ServiceList]. This may be passed into other bindings call that may
// need context on the available services for this client.
//
// Parameters:
// - args[0] - Javascript object that has functions that implement the
// [bindings.TrackServicesCallback] interface.
func (c *Cmix) TrackServices(_ js.Value, args []js.Value) interface{} {
c.api.TrackServices(
&trackServicesCallback{utils.WrapCB(args[0], "Callback")})
return nil
}
...@@ -35,22 +35,62 @@ func Test_newGroupChatJS(t *testing.T) { ...@@ -35,22 +35,62 @@ func Test_newGroupChatJS(t *testing.T) {
} }
} }
// Tests that GroupChat has all the methods that [bindings.GroupChat] has.
func Test_GroupChatMethods(t *testing.T) {
gcType := reflect.TypeOf(&GroupChat{})
binGcType := reflect.TypeOf(&bindings.GroupChat{})
if binGcType.NumMethod() != gcType.NumMethod() {
t.Errorf("WASM GroupChat object does not have all methods from "+
"bindings.\nexpected: %d\nreceived: %d",
binGcType.NumMethod(), gcType.NumMethod())
}
for i := 0; i < binGcType.NumMethod(); i++ {
method := binGcType.Method(i)
if _, exists := gcType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
// Tests that the map representing Group returned by newGroupJS contains all of // Tests that the map representing Group returned by newGroupJS contains all of
// the methods on Group. // the methods on Group.
func Test_newGroupJS(t *testing.T) { func Test_newGroupJS(t *testing.T) {
gType := reflect.TypeOf(&Group{}) grpType := reflect.TypeOf(&Group{})
g := newGroupJS(&bindings.Group{}) g := newGroupJS(&bindings.Group{})
if len(g) != gType.NumMethod() { if len(g) != grpType.NumMethod() {
t.Errorf("Group JS object does not have all methods."+ t.Errorf("Group JS object does not have all methods."+
"\nexpected: %d\nreceived: %d", gType.NumMethod(), len(g)) "\nexpected: %d\nreceived: %d", grpType.NumMethod(), len(g))
} }
for i := 0; i < gType.NumMethod(); i++ { for i := 0; i < grpType.NumMethod(); i++ {
method := gType.Method(i) method := grpType.Method(i)
if _, exists := g[method.Name]; !exists { if _, exists := g[method.Name]; !exists {
t.Errorf("Method %s does not exist.", method.Name) t.Errorf("Method %s does not exist.", method.Name)
} }
} }
} }
// Tests that Group has all the methods that [bindings.Group] has.
func Test_GroupMethods(t *testing.T) {
grpType := reflect.TypeOf(&Group{})
binGrpType := reflect.TypeOf(&bindings.Group{})
if binGrpType.NumMethod() != grpType.NumMethod() {
t.Errorf("WASM Group object does not have all methods from bindings."+
"\nexpected: %d\nreceived: %d",
binGrpType.NumMethod(), grpType.NumMethod())
}
for i := 0; i < binGrpType.NumMethod(); i++ {
method := binGrpType.Method(i)
if _, exists := grpType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package wasm package wasm
import ( import (
"gitlab.com/elixxir/client/bindings"
"reflect" "reflect"
"testing" "testing"
) )
...@@ -34,6 +35,26 @@ func Test_newStopperJS(t *testing.T) { ...@@ -34,6 +35,26 @@ func Test_newStopperJS(t *testing.T) {
} }
} }
// Tests that Stopper has all the methods that [bindings.Stopper] has.
func Test_StopperMethods(t *testing.T) {
stopperType := reflect.TypeOf(&Stopper{})
binStopperType := reflect.TypeOf(bindings.Stopper(&stopper{}))
if binStopperType.NumMethod() != stopperType.NumMethod() {
t.Errorf("WASM Stopper object does not have all methods from bindings."+
"\nexpected: %d\nreceived: %d",
binStopperType.NumMethod(), stopperType.NumMethod())
}
for i := 0; i < binStopperType.NumMethod(); i++ {
method := binStopperType.Method(i)
if _, exists := stopperType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
type stopper struct{} type stopper struct{}
func (s *stopper) Stop() {} func (s *stopper) Stop() {}
...@@ -34,3 +34,24 @@ func Test_newUserDiscoveryJS(t *testing.T) { ...@@ -34,3 +34,24 @@ func Test_newUserDiscoveryJS(t *testing.T) {
} }
} }
} }
// Tests that UserDiscovery has all the methods that [bindings.UserDiscovery]
// has.
func Test_UserDiscoveryMethods(t *testing.T) {
udType := reflect.TypeOf(&UserDiscovery{})
binUdType := reflect.TypeOf(&bindings.UserDiscovery{})
if binUdType.NumMethod() != udType.NumMethod() {
t.Errorf("WASM UserDiscovery object does not have all methods from "+
"bindings.\nexpected: %d\nreceived: %d",
binUdType.NumMethod(), udType.NumMethod())
}
for i := 0; i < binUdType.NumMethod(); i++ {
method := binUdType.Method(i)
if _, exists := udType.MethodByName(method.Name); !exists {
t.Errorf("Method %s does not exist.", method.Name)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment