aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-02 23:29:45 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-02 23:29:45 +0300
commit9dabaa26c7fa9bd79805b0dbd626c5386f805afb (patch)
tree732a49773063d73c5c5576033cd4ab27dbe0ed37 /config
parentc5ea283777ddeb8eecab159acb9cf5de407a7f71 (diff)
Add some basic Session tests
Diffstat (limited to 'config')
-rw-r--r--config/session_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/config/session_test.go b/config/session_test.go
index 780ac6b..ca283d9 100644
--- a/config/session_test.go
+++ b/config/session_test.go
@@ -15,3 +15,73 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package config_test
+
+import (
+ "testing"
+ "maunium.net/go/gomuks/config"
+ "github.com/stretchr/testify/assert"
+ "os"
+)
+
+func TestConfig_NewSession(t *testing.T) {
+ defer os.RemoveAll("/tmp/gomuks-test-7")
+
+ cfg := config.NewConfig("/tmp/gomuks-test-7", "/tmp/gomuks-test-7")
+ cfg.Load()
+ session := cfg.NewSession("@tulir:maunium.net")
+ assert.Equal(t, session.GetUserID(), "@tulir:maunium.net")
+ assert.Empty(t, session.Rooms)
+
+ _, err1 := os.Stat("/tmp/gomuks-test-7/@tulir:maunium.net.session")
+ assert.True(t, os.IsNotExist(err1))
+ assert.Nil(t, session.Save())
+ _, err2 := os.Stat("/tmp/gomuks-test-7/@tulir:maunium.net.session")
+ assert.Nil(t, err2)
+}
+
+func TestSession_Load(t *testing.T) {
+ defer os.RemoveAll("/tmp/gomuks-test-8")
+
+ cfg := config.NewConfig("/tmp/gomuks-test-8", "/tmp/gomuks-test-8")
+ cfg.Load()
+ session := cfg.NewSession("@tulir:maunium.net")
+ session.NextBatch = "foobar"
+ session.FilterID = "1234"
+
+ assert.Nil(t, session.Save())
+
+ cfg = config.NewConfig("/tmp/gomuks-test-8", "/tmp/gomuks-test-8")
+ cfg.LoadSession("@tulir:maunium.net")
+ assert.NotNil(t, cfg.Session)
+ assert.Equal(t, "foobar", cfg.Session.LoadNextBatch("@tulir:maunium.net"))
+ assert.Equal(t, "1234", cfg.Session.LoadFilterID("@tulir:maunium.net"))
+}
+
+func TestSession_Clear(t *testing.T) {
+ defer os.RemoveAll("/tmp/gomuks-test-9")
+
+ cfg := config.NewConfig("/tmp/gomuks-test-9", "/tmp/gomuks-test-9")
+ cfg.Load()
+ session := cfg.NewSession("@tulir:maunium.net")
+ session.NextBatch = "foobar"
+ session.FilterID = "1234"
+
+ assert.Nil(t, session.Save())
+
+ cfg = config.NewConfig("/tmp/gomuks-test-9", "/tmp/gomuks-test-9")
+ cfg.LoadSession("@tulir:maunium.net")
+ assert.NotNil(t, cfg.Session)
+ assert.Equal(t, "foobar", cfg.Session.LoadNextBatch("@tulir:maunium.net"))
+ assert.Equal(t, "1234", cfg.Session.LoadFilterID("@tulir:maunium.net"))
+
+ cfg.Session.Clear()
+ assert.Empty(t, cfg.Session.FilterID)
+ assert.Empty(t, cfg.Session.NextBatch)
+ assert.Empty(t, cfg.Session.Rooms)
+
+ cfg = config.NewConfig("/tmp/gomuks-test-9", "/tmp/gomuks-test-9")
+ cfg.LoadSession("@tulir:maunium.net")
+ assert.Empty(t, cfg.Session.FilterID)
+ assert.Empty(t, cfg.Session.NextBatch)
+ assert.Empty(t, cfg.Session.Rooms)
+}