go.dedis.ch/onet/v3@v3.2.11-0.20210930124529-e36530bca7ef/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 := NewTCPTest(tSuite) 24 defer l.CloseAll() 25 26 c := l.NewServer(tSuite, 2050) 27 defer c.Close() 28 29 stats := c.GetStatus() 30 a := ServiceFactory.RegisteredServiceNames() 31 services := strings.Split(stats.Field["Available_Services"], ",") 32 assert.Equal(t, len(services), len(a)) 33 } 34 35 type dummyTestReporter struct { 36 Status int 37 } 38 39 func (d *dummyTestReporter) GetStatus() *Status { 40 return &Status{map[string]string{"Connections": strconv.Itoa(d.Status)}} 41 }