Skip to content

Commit

Permalink
Add more hub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Jan 4, 2024
1 parent 55ef86a commit b5a0c0e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions service/hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ func (s *HubSuite) Test_MapShipMessageExchangeState() {
state = sut.mapShipMessageExchangeState(ship.SmeHelloStateAbort, ski)
assert.Equal(s.T(), ConnectionStateNone, state)

state = sut.mapShipMessageExchangeState(ship.SmeHelloStateRemoteAbortDone, ski)
assert.Equal(s.T(), ConnectionStateRemoteDeniedTrust, state)

state = sut.mapShipMessageExchangeState(ship.SmePinStateCheckInit, ski)
assert.Equal(s.T(), ConnectionStatePin, state)

Expand Down Expand Up @@ -267,6 +270,15 @@ func (s *HubSuite) Test_RegisterConnection() {
assert.NotNil(s.T(), con)
}

func (s *HubSuite) Test_Shutdown() {
sut := connectionsHubImpl{
connections: make(map[string]*ship.ShipConnection),
mdns: s.mdnsService,
}
s.mdnsService.EXPECT().ShutdownMdnsService()
sut.Shutdown()
}

func (s *HubSuite) Test_IncreaseConnectionAttemptCounter() {

// we just need a dummy for this test
Expand Down Expand Up @@ -396,3 +408,41 @@ func (s *HubSuite) Test_CancelPairingWithSKI() {
sut.CancelPairingWithSKI(ski)
assert.Equal(s.T(), 0, len(sut.connectionAttemptRunning))
}

func (s *HubSuite) Test_ReportMdnsEntries() {
localService := &ServiceDetails{
SKI: "localSKI",
}
sut := connectionsHubImpl{
connections: make(map[string]*ship.ShipConnection),
connectionAttemptCounter: make(map[string]int),
connectionAttemptRunning: make(map[string]bool),
remoteServices: make(map[string]*ServiceDetails),
serviceProvider: s.serviceProvider,
localService: localService,
}

testski1 := "test1"
testski2 := "test2"

entries := make(map[string]*MdnsEntry)

s.serviceProvider.EXPECT().VisibleMDNSRecordsUpdated(gomock.Any()).AnyTimes()
sut.ReportMdnsEntries(entries)

entries[testski1] = &MdnsEntry{
Ski: testski1,
}
service1 := sut.ServiceForSKI(testski1)
service1.Trusted = true
service1.IPv4 = "127.0.0.1"

entries[testski2] = &MdnsEntry{
Ski: testski2,
}
service2 := sut.ServiceForSKI(testski2)
service2.Trusted = true
service2.IPv4 = "127.0.0.1"

sut.ReportMdnsEntries(entries)
}
1 change: 1 addition & 0 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (s *ServiceSuite) BeforeTest(suiteName, testName string) {

s.logging = mocks.NewLogging(s.T())
s.logging.On("Info", mock.Anything, mock.Anything).Maybe()
s.logging.On("Debug", mock.Anything, mock.Anything).Maybe()

certificate := tls.Certificate{}
s.config, _ = NewConfiguration(
Expand Down

0 comments on commit b5a0c0e

Please sign in to comment.