func TestCreateTag(t *testing.T) {
	form := url.Values{}
	form.Add("name", names[0])
	body := strings.NewReader(form.Encode())
	r := httptest.NewRequest("POST", "/tags/create", body)
	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	w := httptest.NewRecorder()
	err := resource.AddUserSessionCookie(w, r, 1)
	if err != nil {
		t.Errorf("tagactions: error setting session %s", err)
	}
	err = HandleCreate(w, r)
	if err != nil {
		t.Fatalf("tagactions: error handling HandleCreate %s", err)
	}
	if w.Code != http.StatusFound {
		t.Errorf("tagactions: unexpected response code for HandleCreate expected:%d got:%d", http.StatusFound, w.Code)
	}
	allTag, err := tags.FindAll(tags.Query().Order("id desc"))
	if err != nil || len(allTag) == 0 {
		t.Fatalf("tagactions: error finding created tag %s", err)
	}
	newTag := allTag[0]
	if newTag.ID != 1 || newTag.Name != names[0] {
		t.Errorf("tagactions: error with created tag values: %v %s", newTag.ID, newTag.Name)
	}
}
Test POST /tags/create
package tagactions
import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"net/url"
	"strings"
	"testing"
	"github.com/fragmenta/mux"
	"github.com/fragmenta/query"
	"github.com/fragmenta/fragmenta-cms/src/lib/resource"
	"github.com/fragmenta/fragmenta-cms/src/tags"
)
var names = []string{"foo", "bar"}
func TestSetup(t *testing.T) {
	err := resource.SetupTestDatabase(3)
	if err != nil {
		fmt.Printf("tags: Setup db failed %s", err)
	}
	resource.SetupAuthorisation()
	resource.SetupView(3)
	router := mux.New()
	mux.SetDefault(router)
	router.Add("/tags", nil)
	router.Add("/tags/create", nil)
	router.Add("/tags/create", nil).Post()
	router.Add("/tags/login", nil)
	router.Add("/tags/login", nil).Post()
	router.Add("/tags/login", nil).Post()
	router.Add("/tags/logout", nil).Post()
	router.Add("/tags/{id:\\d+}/update", nil)
	router.Add("/tags/{id:\\d+}/update", nil).Post()
	router.Add("/tags/{id:\\d+}/destroy", nil).Post()
	router.Add("/tags/{id:\\d+}", nil)
	query.ExecSQL("delete from tags;")
	query.ExecSQL("ALTER SEQUENCE tags_id_seq RESTART WITH 1;")
}
func TestShowCreateTag(t *testing.T) {
	r := httptest.NewRequest("GET", "/tags/create", nil)
	w := httptest.NewRecorder()
	err := resource.AddUserSessionCookie(w, r, 1)
	if err != nil {
		t.Errorf("tagactions: error setting session %s", err)
	}
	err = HandleCreateShow(w, r)
	if err != nil || w.Code != http.StatusOK {
		t.Errorf("tagactions: error handling HandleCreateShow %s", err)
	}
	pattern := "resource-update-form"
	if !strings.Contains(w.Body.String(), pattern) {
		t.Errorf("tagactions: unexpected response for HandleCreateShow expected:%s got:%s", pattern, w.Body.String())
	}
}