-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b312edb
commit f22c89c
Showing
8 changed files
with
334 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
package bridge | ||
|
||
import ( | ||
"github.com/h2non/gock" | ||
"github.com/systemli/ticker/internal/config" | ||
"github.com/systemli/ticker/internal/storage" | ||
) | ||
|
||
func (s *BridgeTestSuite) TestSignalGroupSend() { | ||
s.Run("when signalGroup is inactive", func() { | ||
bridge := s.signalGroupBridge(config.Config{}, &storage.MockStorage{}) | ||
|
||
err := bridge.Send(tickerWithoutBridges, &messageWithoutBridges) | ||
s.NoError(err) | ||
}) | ||
|
||
s.Run("when signalGroup is active but signal-cli api fails", func() { | ||
bridge := s.signalGroupBridge(config.Config{ | ||
SignalGroup: config.SignalGroup{ | ||
ApiUrl: "https://signal-cli.example.org/api/v1/rpc", | ||
Account: "0123456789", | ||
}, | ||
}, &storage.MockStorage{}) | ||
|
||
gock.New("https://signal-cli.example.org"). | ||
Post("/api/v1/rpc"). | ||
Reply(500) | ||
|
||
err := bridge.Send(tickerWithBridges, &storage.Message{}) | ||
s.Error(err) | ||
s.True(gock.IsDone()) | ||
}) | ||
|
||
s.Run("when response timestamp == 0", func() { | ||
bridge := s.signalGroupBridge(config.Config{ | ||
SignalGroup: config.SignalGroup{ | ||
ApiUrl: "https://signal-cli.example.org/api/v1/rpc", | ||
Account: "0123456789", | ||
}, | ||
}, &storage.MockStorage{}) | ||
|
||
gock.New("https://signal-cli.example.org"). | ||
Post("/api/v1/rpc"). | ||
Reply(200). | ||
JSON(map[string]interface{}{ | ||
"jsonrpc": "2.0", | ||
"result": map[string]int{ | ||
"timestamp": 0, | ||
}, | ||
"id": 1, | ||
}) | ||
|
||
err := bridge.Send(tickerWithBridges, &storage.Message{}) | ||
s.Error(err) | ||
s.True(gock.IsDone()) | ||
}) | ||
|
||
s.Run("happy path", func() { | ||
bridge := s.signalGroupBridge(config.Config{ | ||
SignalGroup: config.SignalGroup{ | ||
ApiUrl: "https://signal-cli.example.org/api/v1/rpc", | ||
Account: "0123456789", | ||
}, | ||
}, &storage.MockStorage{}) | ||
|
||
gock.New("https://signal-cli.example.org"). | ||
Post("/api/v1/rpc"). | ||
Reply(200). | ||
JSON(map[string]interface{}{ | ||
"jsonrpc": "2.0", | ||
"result": map[string]int{ | ||
"timestamp": 1, | ||
}, | ||
"id": 1, | ||
}) | ||
|
||
err := bridge.Send(tickerWithBridges, &storage.Message{}) | ||
s.NoError(err) | ||
s.True(gock.IsDone()) | ||
}) | ||
} | ||
|
||
func (s *BridgeTestSuite) TestSignalDelete() { | ||
s.Run("when signal not connected", func() { | ||
bridge := s.signalGroupBridge(config.Config{}, &storage.MockStorage{}) | ||
|
||
err := bridge.Delete(tickerWithoutBridges, &messageWithoutBridges) | ||
s.NoError(err) | ||
}) | ||
|
||
s.Run("when message has no signal meta", func() { | ||
bridge := s.signalGroupBridge(config.Config{ | ||
SignalGroup: config.SignalGroup{ | ||
ApiUrl: "https://signal-cli.example.org/api/v1/rpc", | ||
Account: "0123456789", | ||
}, | ||
}, &storage.MockStorage{}) | ||
|
||
err := bridge.Delete(tickerWithBridges, &messageWithoutBridges) | ||
s.NoError(err) | ||
}) | ||
|
||
s.Run("when signal is inactive", func() { | ||
bridge := s.signalGroupBridge(config.Config{}, &storage.MockStorage{}) | ||
|
||
err := bridge.Delete(tickerWithBridges, &messageWithoutBridges) | ||
s.NoError(err) | ||
}) | ||
|
||
s.Run("when delete fails", func() { | ||
bridge := s.signalGroupBridge(config.Config{ | ||
SignalGroup: config.SignalGroup{ | ||
ApiUrl: "https://signal-cli.example.org/api/v1/rpc", | ||
Account: "0123456789", | ||
}, | ||
}, &storage.MockStorage{}) | ||
|
||
gock.New("https://signal-cli.example.org"). | ||
Post("/api/v1/rpc"). | ||
Reply(500) | ||
|
||
err := bridge.Delete(tickerWithBridges, &messageWithBridges) | ||
s.Error(err) | ||
s.True(gock.IsDone()) | ||
}) | ||
|
||
s.Run("happy path", func() { | ||
bridge := s.signalGroupBridge(config.Config{ | ||
SignalGroup: config.SignalGroup{ | ||
ApiUrl: "https://signal-cli.example.org/api/v1/rpc", | ||
Account: "0123456789", | ||
}, | ||
}, &storage.MockStorage{}) | ||
|
||
gock.New("https://signal-cli.example.org"). | ||
Post("/api/v1/rpc"). | ||
Reply(200). | ||
JSON(map[string]interface{}{ | ||
"jsonrpc": "2.0", | ||
"result": map[string]int{ | ||
"timestamp": 1, | ||
}, | ||
"id": 1, | ||
}) | ||
|
||
err := bridge.Delete(tickerWithBridges, &messageWithBridges) | ||
s.NoError(err) | ||
s.True(gock.IsDone()) | ||
}) | ||
} | ||
|
||
func (s *BridgeTestSuite) signalGroupBridge(config config.Config, storage storage.Storage) *SignalGroupBridge { | ||
return &SignalGroupBridge{ | ||
config: config, | ||
storage: storage, | ||
} | ||
} |
Oops, something went wrong.