mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Later layers speak categories and records, and export needs nothing else. Ordering rows once in the exporter fixes Firefox history, written least visited first.
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package category
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestString(t *testing.T) {
|
|
tests := []struct {
|
|
c Category
|
|
want string
|
|
}{
|
|
{Password, "password"},
|
|
{Cookie, "cookie"},
|
|
{Bookmark, "bookmark"},
|
|
{History, "history"},
|
|
{Download, "download"},
|
|
{CreditCard, "creditcard"},
|
|
{Extension, "extension"},
|
|
{LocalStorage, "localstorage"},
|
|
{SessionStorage, "sessionstorage"},
|
|
{Category(0), "unknown"},
|
|
{Category(999), "unknown"},
|
|
}
|
|
for _, tt := range tests {
|
|
assert.Equal(t, tt.want, tt.c.String())
|
|
}
|
|
}
|
|
|
|
func TestAll(t *testing.T) {
|
|
assert.Equal(t, []Category{
|
|
Password, Cookie, Bookmark, History, Download, CreditCard, Extension, LocalStorage, SessionStorage,
|
|
}, All())
|
|
}
|
|
|
|
func TestAll_ReturnsFreshSlice(t *testing.T) {
|
|
All()[0] = SessionStorage
|
|
assert.Equal(t, Password, All()[0])
|
|
}
|
|
|
|
func TestParse_RoundTrip(t *testing.T) {
|
|
for _, c := range All() {
|
|
got, err := Parse(c.String())
|
|
require.NoError(t, err)
|
|
assert.Equal(t, c, got)
|
|
}
|
|
}
|
|
|
|
func TestParse_Unknown(t *testing.T) {
|
|
for _, s := range []string{"", "unknown", "all", "Password", " cookie"} {
|
|
got, err := Parse(s)
|
|
require.EqualError(t, err, "unknown category: \""+s+"\"")
|
|
assert.Zero(t, got)
|
|
}
|
|
}
|
|
|
|
func TestZeroIsNone(t *testing.T) {
|
|
var c Category
|
|
assert.NotContains(t, All(), c)
|
|
}
|