Commit 849a4d22 authored by santiaago's avatar santiaago
Browse files

add test to themes pkg

parent ce157872
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
package themes

import (
	"net/http"
	"testing"

	"github.com/taironas/route"
	tgTesting "github.com/taironas/tinygraphs/testing"
)

func TestTheme(t *testing.T) {

	r := new(route.Router)
	r.HandleFunc("/themes", Theme)
	r.HandleFunc("/themes/:key", Theme)

	test := tgTesting.GenerateHandlerFunc(t, Theme)
	for _, p := range tgTesting.GoodParams {
		recorder := test("/themes", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		recorder = test("/themes/somekey", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}

	for _, p := range tgTesting.BadParams {
		recorder := test("/themes", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
		recorder = test("/themes/somekey", "GET", p, r)
		if recorder.Code != http.StatusOK {
			t.Errorf("returned %v. Expected %v.", recorder.Code, http.StatusOK)
		}
	}
}