Skip to content

Commit

Permalink
fix(matrix): allow title to be passed as prop (#203)
Browse files Browse the repository at this point in the history
- fix(matrix): allow room prop alias
- test(matrix): add tests for url props
  • Loading branch information
piksel authored Oct 9, 2021
1 parent b1a59a7 commit 2951098
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/services/matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

*matrix://__`user`__:__`password`__@__`host`__:__`port`__/[?rooms=__`!roomID1`__[,__`roomAlias2`__]][&disableTLS=yes]*

--8<-- "docs/services/matrix/config.md"

## Authentication

If no `user` is specified, the `password` is treated as the authentication token. This means that no matter what login
Expand Down
3 changes: 2 additions & 1 deletion pkg/services/matrix/matrix_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ type Config struct {
Password string
DisableTLS bool `key:"disableTLS" default:"No"`
Host string
Rooms []string `key:"rooms" optional:""`
Rooms []string `key:"rooms,room" optional:""`
Title string `key:"title" default:""`
}

// GetURL returns a URL representation of it's current field values
Expand Down
22 changes: 20 additions & 2 deletions pkg/services/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,26 @@ var _ = Describe("the matrix service", func() {
})

Describe("creating configurations", func() {
When("given an url", func() {
When("given an url with title prop", func() {
It("should not throw an error", func() {
serviceURL := util.URLMust(`matrix://user:pass@mockserver?rooms=room1&title=Better%20Off%20Alone`)
Expect((&Config{}).SetURL(serviceURL)).To(Succeed())
})
})

When("given an url with the prop `room`", func() {
It("should treat is as an alias for `rooms`", func() {
serviceURL := util.URLMust(`matrix://user:pass@mockserver?room=room1`)
config := Config{}
Expect(config.SetURL(serviceURL)).To(Succeed())
Expect(config.Rooms).To(ContainElement("#room1"))
})
})
When("given an url with invalid props", func() {
It("should return an error", func() {
serviceURL := util.URLMust(`matrix://user:pass@mockserver?channels=room1,room2`)
Expect((&Config{}).SetURL(serviceURL)).To(HaveOccurred())
})
})
When("parsing the configuration URL", func() {
It("should be identical after de-/serialization", func() {
Expand Down Expand Up @@ -130,7 +148,7 @@ var _ = Describe("the matrix service", func() {
testutils.TestConfigSetInvalidQueryValue(&Config{}, "matrix://user:pass@host/?foo=bar")

testutils.TestConfigGetEnumsCount(&Config{}, 0)
testutils.TestConfigGetFieldsCount(&Config{}, 2)
testutils.TestConfigGetFieldsCount(&Config{}, 4)
})
})

Expand Down

0 comments on commit 2951098

Please sign in to comment.