dispatch/server/index_data_test.go

61 lines
1.5 KiB
Go
Raw Normal View History

package server
import (
"net/http"
"net/url"
"testing"
"github.com/khlieng/dispatch/storage"
"github.com/stretchr/testify/assert"
)
func TestGetTabFromPath(t *testing.T) {
cases := []struct {
input *http.Request
expectedTab Tab
}{
{
&http.Request{
URL: &url.URL{Path: "/init"},
Header: http.Header{"Referer": []string{"/chat.freenode.net/%23r%2Fstuff%2F"}},
},
2020-06-15 08:58:51 +00:00
Tab{storage.Tab{Network: "chat.freenode.net", Name: "#r/stuff/"}},
}, {
&http.Request{
URL: &url.URL{Path: "/init"},
Header: http.Header{"Referer": []string{"/chat.freenode.net/%23r%2Fstuff"}},
},
2020-06-15 08:58:51 +00:00
Tab{storage.Tab{Network: "chat.freenode.net", Name: "#r/stuff"}},
}, {
&http.Request{
URL: &url.URL{Path: "/init"},
Header: http.Header{"Referer": []string{"/chat.freenode.net/%23stuff"}},
},
2020-06-15 08:58:51 +00:00
Tab{storage.Tab{Network: "chat.freenode.net", Name: "#stuff"}},
}, {
&http.Request{
URL: &url.URL{Path: "/init"},
Header: http.Header{"Referer": []string{"/chat.freenode.net/stuff"}},
},
2020-06-15 08:58:51 +00:00
Tab{storage.Tab{Network: "chat.freenode.net", Name: "stuff"}},
}, {
&http.Request{
URL: &url.URL{Path: "/init"},
Header: http.Header{"Referer": []string{"/data/chat.freenode.net/%23apples"}},
},
Tab{},
2018-11-07 01:07:23 +00:00
}, {
&http.Request{
URL: &url.URL{Path: "/ws/chat.freenode.net"},
},
2020-06-15 08:58:51 +00:00
Tab{storage.Tab{Network: "chat.freenode.net"}},
},
}
for _, tc := range cases {
tab, err := tabFromRequest(tc.input)
assert.Nil(t, err)
assert.Equal(t, tc.expectedTab, tab)
}
}