gopkg.in/dedis/onet.v2@v2.0.0-20181115163211-c8f3724038a7/status_test.go (about)

     1  package onet
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"strconv"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestSRStruct(t *testing.T) {
    13  	srs := newStatusReporterStruct()
    14  	assert.NotNil(t, srs)
    15  	dtr := &dummyTestReporter{5}
    16  	srs.RegisterStatusReporter("Dummy", dtr)
    17  	assert.Equal(t, srs.ReportStatus()["Dummy"].Field["Connections"], "5")
    18  	dtr.Status = 10
    19  	assert.Equal(t, srs.ReportStatus()["Dummy"].Field["Connections"], "10")
    20  }
    21  
    22  func TestStatusHost(t *testing.T) {
    23  	l := NewLocalTest(tSuite)
    24  	defer l.CloseAll()
    25  
    26  	c := newTCPServer(tSuite, 0, l.path)
    27  	c.StartInBackground()
    28  
    29  	defer c.Close()
    30  	stats := c.GetStatus()
    31  	a := ServiceFactory.RegisteredServiceNames()
    32  	services := strings.Split(stats.Field["Available_Services"], ",")
    33  	assert.Equal(t, len(services), len(a))
    34  }
    35  
    36  type dummyTestReporter struct {
    37  	Status int
    38  }
    39  
    40  func (d *dummyTestReporter) GetStatus() *Status {
    41  	return &Status{map[string]string{"Connections": strconv.Itoa(d.Status)}}
    42  }