aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml18
-rw-r--r--README.md5
-rw-r--r--config/session.go2
-rw-r--r--go.mod15
-rw-r--r--matrix/pushrules/pushrules_test.go253
5 files changed, 290 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..47aae08
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+language: go
+go_import_path: maunium.net/go/gomuks
+go:
+ - "1.10"
+notifications:
+ email: false
+install:
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
+ - chmod +x ./cc-test-reporter
+ - go get -u github.com/stretchr/testify/assert
+ - go get
+before_script:
+ - ./cc-test-reporter before-build
+script:
+ - go test -v -race ./... -coverprofile c.out
+ - go vet ./...
+after_script:
+ - ./cc-test-reporter after-build --coverage-input-type gocov --exit-code $TRAVIS_TEST_RESULT
diff --git a/README.md b/README.md
index fcf93e8..979a215 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,9 @@
![Languages](https://img.shields.io/github/languages/top/tulir/gomuks.svg)
[![License](https://img.shields.io/github/license/tulir/gomuks.svg)](LICENSE)
[![Release](https://img.shields.io/github/release/tulir/gomuks/all.svg)](https://github.com/tulir/gomuks/releases)
-[![Maintainability](https://img.shields.io/codeclimate/maintainability/tulir/gomuks.svg)](https://codeclimate.com/github/tulir/gomuks)
-[![Coverage](https://img.shields.io/codeclimate/coverage/tulir/gomuks.svg)](https://codeclimate.com/github/tulir/gomuks)
+[![Build Status](https://travis-ci.org/tulir/gomuks.svg?branch=master)](https://travis-ci.org/tulir/gomuks)
+[![Maintainability](https://shields-staging.herokuapp.com/codeclimate/maintainability/tulir/gomuks.svg)](https://codeclimate.com/github/tulir/gomuks)
+[![Coverage](https://shields-staging.herokuapp.com/codeclimate/coverage/tulir/gomuks.svg)](https://codeclimate.com/github/tulir/gomuks)
![Preview](https://img.mau.lu/tlVuN.png)
diff --git a/config/session.go b/config/session.go
index d12bc20..26d0daa 100644
--- a/config/session.go
+++ b/config/session.go
@@ -29,7 +29,7 @@ import (
type Session struct {
UserID string `json:"-"`
- path string `json:"-"`
+ path string
AccessToken string
NextBatch string
FilterID string
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..6ff237c
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,15 @@
+module "github.com/tulir/gomuks"
+
+require (
+ "github.com/gdamore/encoding" v0.0.0-20151215212835-b23993cbb635
+ "github.com/gdamore/tcell" v0.0.0-20180402155337-2548ddfbd80a
+ "github.com/lucasb-eyer/go-colorful" v0.0.0-20170903184257-231272389856
+ "github.com/mattn/go-runewidth" v0.0.2
+ "github.com/zyedidia/clipboard" v0.0.0-20180208191628-4611e809d8b1
+ "github.com/zyedidia/glob" v0.0.0-20170209203856-dd4023a66dc3
+ "golang.org/x/text" v0.0.0-20171214130843-f21a4dfb5e38
+ "gopkg.in/yaml.v2" v1.2.1-gopkgin-v2.2.1
+ "maunium.net/go/gomatrix" v0.0.0-20180318193435-618319f327ac
+ "maunium.net/go/gomuks" v0.0.0-20180410183527-75a0945a83fb
+ "maunium.net/go/tview" v0.0.0-20180330155404-723cca66ac4d
+)
diff --git a/matrix/pushrules/pushrules_test.go b/matrix/pushrules/pushrules_test.go
new file mode 100644
index 0000000..7e0e72e
--- /dev/null
+++ b/matrix/pushrules/pushrules_test.go
@@ -0,0 +1,253 @@
+// gomuks - A terminal Matrix client written in Go.
+// Copyright (C) 2018 Tulir Asokan
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package pushrules
+
+import (
+ "encoding/json"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "maunium.net/go/gomatrix"
+)
+
+var mapExamplePushRules map[string]interface{}
+
+func init() {
+ mapExamplePushRules = make(map[string]interface{})
+ json.Unmarshal([]byte(JSONExamplePushRules), &mapExamplePushRules)
+}
+
+func TestEventToPushRules(t *testing.T) {
+ event := &gomatrix.Event{
+ Type: "m.push_rules",
+ Timestamp: 1523380910,
+ Content: mapExamplePushRules,
+ }
+ pushRuleset, err := EventToPushRules(event)
+ assert.Nil(t, err)
+ assert.NotNil(t, pushRuleset)
+
+ assert.IsType(t, pushRuleset.Override, PushRuleArray{})
+ assert.IsType(t, pushRuleset.Content, PushRuleArray{})
+ assert.IsType(t, pushRuleset.Room, PushRuleMap{})
+ assert.IsType(t, pushRuleset.Sender, PushRuleMap{})
+ assert.IsType(t, pushRuleset.Underride, PushRuleArray{})
+ assert.Len(t, pushRuleset.Override, 2)
+ assert.Len(t, pushRuleset.Content, 1)
+ assert.Empty(t, pushRuleset.Room.Map)
+ assert.Empty(t, pushRuleset.Sender.Map)
+ assert.Len(t, pushRuleset.Underride, 6)
+
+ assert.Len(t, pushRuleset.Content[0].Actions, 3)
+ assert.True(t, pushRuleset.Content[0].Default)
+ assert.True(t, pushRuleset.Content[0].Enabled)
+ assert.Empty(t, pushRuleset.Content[0].Conditions)
+ assert.Equal(t, "alice", pushRuleset.Content[0].Pattern)
+ assert.Equal(t, ".m.rule.contains_user_name", pushRuleset.Content[0].RuleID)
+
+ assert.False(t, pushRuleset.Override[0].Actions.Should().Notify)
+ assert.True(t, pushRuleset.Override[0].Actions.Should().NotifySpecified)
+}
+
+const JSONExamplePushRules = `{
+ "global": {
+ "content": [
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "sound",
+ "value": "default"
+ },
+ {
+ "set_tweak": "highlight"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "pattern": "alice",
+ "rule_id": ".m.rule.contains_user_name"
+ }
+ ],
+ "override": [
+ {
+ "actions": [
+ "dont_notify"
+ ],
+ "conditions": [],
+ "default": true,
+ "enabled": false,
+ "rule_id": ".m.rule.master"
+ },
+ {
+ "actions": [
+ "dont_notify"
+ ],
+ "conditions": [
+ {
+ "key": "content.msgtype",
+ "kind": "event_match",
+ "pattern": "m.notice"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.suppress_notices"
+ }
+ ],
+ "room": [],
+ "sender": [],
+ "underride": [
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "sound",
+ "value": "ring"
+ },
+ {
+ "set_tweak": "highlight",
+ "value": false
+ }
+ ],
+ "conditions": [
+ {
+ "key": "type",
+ "kind": "event_match",
+ "pattern": "m.call.invite"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.call"
+ },
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "sound",
+ "value": "default"
+ },
+ {
+ "set_tweak": "highlight"
+ }
+ ],
+ "conditions": [
+ {
+ "kind": "contains_display_name"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.contains_display_name"
+ },
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "sound",
+ "value": "default"
+ },
+ {
+ "set_tweak": "highlight",
+ "value": false
+ }
+ ],
+ "conditions": [
+ {
+ "is": "2",
+ "kind": "room_member_count"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.room_one_to_one"
+ },
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "sound",
+ "value": "default"
+ },
+ {
+ "set_tweak": "highlight",
+ "value": false
+ }
+ ],
+ "conditions": [
+ {
+ "key": "type",
+ "kind": "event_match",
+ "pattern": "m.room.member"
+ },
+ {
+ "key": "content.membership",
+ "kind": "event_match",
+ "pattern": "invite"
+ },
+ {
+ "key": "state_key",
+ "kind": "event_match",
+ "pattern": "@alice:example.com"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.invite_for_me"
+ },
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "highlight",
+ "value": false
+ }
+ ],
+ "conditions": [
+ {
+ "key": "type",
+ "kind": "event_match",
+ "pattern": "m.room.member"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.member_event"
+ },
+ {
+ "actions": [
+ "notify",
+ {
+ "set_tweak": "highlight",
+ "value": false
+ }
+ ],
+ "conditions": [
+ {
+ "key": "type",
+ "kind": "event_match",
+ "pattern": "m.room.message"
+ }
+ ],
+ "default": true,
+ "enabled": true,
+ "rule_id": ".m.rule.message"
+ }
+ ]
+ }
+}`