Skip to content
Snippets Groups Projects
Select Git revision
  • c747aa25fd55f8bcf36728610bcefdcaaaabff06
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

stoppable_test.go

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)
    	}
    }