Skip to content
Snippets Groups Projects
Select Git revision
  • f4db0a78b7cc4d241c0021fa464411be11f3a19d
  • release default
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • master protected
  • XX-4688/DbEncoding
  • hotfix/update
  • @XX-4682/Files
  • hotfix/XX-4655
  • dev protected
  • project/HavenNotifications
  • XX-4602/SilentMessageType
  • jono/npmTest
  • wasmTest2
  • XX-4461/FileUpload
  • XX-4505/blockuser
  • XX-4441
  • Jakub/Emoji-CI-Test
  • testing/websockets
  • fastReg
  • fast-registration
  • NewHostPool
  • v0.3.22
  • v0.3.21
  • v0.3.20
  • v0.3.18
  • v0.3.17
  • v0.3.16
  • v0.3.15
  • v0.3.14
  • v0.3.13
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • 812b395df518ce096d01d5292596ca26f8fe92d9c4487ddfa515e190a51aa1a1
  • 76ba08e2dfa1798412a265404fa271840b52c035869111fce8e8cdb23a036a5a
41 results

wasm_exec.js

Blame
  • params_test.go 1.85 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package fileTransfer
    
    import (
    	"bytes"
    	"encoding/json"
    	"gitlab.com/elixxir/client/cmix"
    	"reflect"
    	"testing"
    )
    
    // Tests that no data is lost when marshaling and unmarshalling the Params
    // object.
    func TestParams_MarshalUnmarshal(t *testing.T) {
    	// Construct a set of params
    	p := DefaultParams()
    
    	// Marshal the params
    	data, err := json.Marshal(&p)
    	if err != nil {
    		t.Fatalf("Marshal error: %v", err)
    	}
    
    	// Unmarshal the params object
    	received := Params{}
    	err = json.Unmarshal(data, &received)
    	if err != nil {
    		t.Fatalf("Unmarshal error: %v", err)
    	}
    
    	// Re-marshal this params object
    	data2, err := json.Marshal(received)
    	if err != nil {
    		t.Fatalf("Marshal error: %v", err)
    	}
    
    	// Check that they match (it is done this way to avoid false failures with
    	// the reflect.DeepEqual function and pointers)
    	if !bytes.Equal(data, data2) {
    		t.Fatalf("Data was lost in marshal/unmarshal.")
    	}
    
    }
    
    // Tests that DefaultParams returns a Params object with the expected defaults.
    func TestDefaultParams(t *testing.T) {
    	expected := Params{
    		MaxThroughput: defaultMaxThroughput,
    		SendTimeout:   defaultSendTimeout,
    		Cmix:          cmix.GetDefaultCMIXParams(),
    	}
    	received := DefaultParams()
    	received.Cmix.Stop = expected.Cmix.Stop
    
    	if !reflect.DeepEqual(expected, received) {
    		t.Errorf("Received Params does not match expected."+
    			"\nexpected: %+v\nreceived: %+v", expected, received)
    	}
    }