// Copyright (C) 2019 Marius Schellenberger

package cache

import (
	"git.giftfish.de/ston1th/gowiki/pkg/core"
	"testing"
)

func TestCache(t *testing.T) {
	title := "test/page"
	pages := []*core.Page{
		&core.Page{
			Title:    title,
			Markdown: "page v1",
		},
		&core.Page{
			Title:    title,
			Markdown: "page v2",
		},
	}
	c := NewCache()
	t.Run("Add", func(t *testing.T) {
		c.Add(title, pages[0])
	})
	t.Run("Get", func(t *testing.T) {
		p := c.Get(title)
		if p.Markdown != pages[0].Markdown {
			t.Fail()
		}
	})
	t.Run("Add", func(t *testing.T) {
		c.Add(title, pages[1])
	})
	t.Run("Get", func(t *testing.T) {
		p := c.Get(title)
		if p.Markdown == pages[0].Markdown {
			t.Fail()
		}
	})
	t.Run("Delete", func(t *testing.T) {
		c.Delete(title)
	})
	t.Run("Get", func(t *testing.T) {
		p := c.Get(title)
		if p != nil {
			t.Fail()
		}
	})
}
