~evanj/cms

ref: 356e3f389fe3e9167cffb270f41b6f2b22eb202a cms/internal/c/redirect/redirect_test.go -rw-r--r-- 764 bytes
356e3f38Evan J Feat(context): Completed adding context to data layer. Refactored tests 1 year, 22 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package redirect_test

import (
	"log"
	"net/http"
	"net/http/httptest"
	"testing"

	"git.sr.ht/~evanj/cms/internal/c"
	"git.sr.ht/~evanj/cms/internal/c/redirect"
	"github.com/bmizerany/assert"
	gomock "github.com/golang/mock/gomock"
)

var ctx = gomock.Any()

func TestRedirect(t *testing.T) {
	t.Parallel()

	var (
		ctrl = gomock.NewController(t)
		db   = redirect.NewMockdber(ctrl)
		l    *log.Logger
		s    = redirect.New(c.New(l, db, true, "test"), l, db)
		ts   = httptest.NewServer(s)
	)

	t.Run("good", func(t *testing.T) {
		res, _ := http.Get(ts.URL + "?url=/space/21")
		assert.Equal(t, res.StatusCode, http.StatusOK)
	})

	t.Run("empty", func(t *testing.T) {
		res, _ := http.Get(ts.URL)
		assert.Equal(t, res.StatusCode, http.StatusBadRequest)
	})
}