Skip to content

Commit

Permalink
Added tests for Sites' Encode/Decode
Browse files Browse the repository at this point in the history
  • Loading branch information
ymkjp committed Feb 15, 2019
1 parent 8e6fb0f commit 154e2b3
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
51 changes: 51 additions & 0 deletions al2/web/albert_sites_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package web

import (
"bytes"
"github.com/ToQoz/gopwt/assert"
"github.com/google/uuid"
"strings"
"testing"
)

func newAlbertConfigDict() ConfigDict {
c1 := &SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Trigger: "foo",
Name: "Sample description",
Url: "https://foo.example.com/{query}/",
}
c2 := &SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Trigger: "bar",
Name: "Sample description",
Url: "https://bar.example.com/{query}/",
}
dict := make(ConfigDict)
dict[c1.Id()] = c1
dict[c2.Id()] = c2
return dict
}

func TestAlbertSites_Encode(t *testing.T) {
dict := newAlbertConfigDict()
sites := AlbertSites{}
json, err := sites.Encode(dict)
assert.OK(t, json != nil)
assert.OK(t, len(json) > 0)
assert.OK(t, err == nil)
}

func TestAlbertSites_Decode(t *testing.T) {
dict := newAlbertConfigDict()
sites := AlbertSites{}
json, _ := sites.Encode(dict)
data := bytes.NewReader(json)
err := sites.Decode(data)
assert.OK(t, len(sites) == 2)
assert.OK(t, err == nil)
}
48 changes: 48 additions & 0 deletions al2/web/alfred_sites_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package web

import (
"bytes"
"github.com/ToQoz/gopwt/assert"
"github.com/google/uuid"
"strings"
"testing"
)

func newAlfredConfigDict() ConfigDict {
c1 := &SiteConfig{
Uuid: strings.ToUpper(uuid.New().String()),
Enabled: true,
Utf8: true,
Trigger: "foo ",
Name: "Sample description",
Url: "https://foo.example.com/%s/",
}
c2 := &SiteConfig{
Trigger: "bar ",
Name: "Sample description",
Url: "https://bar.example.com/%s/",
}
dict := make(ConfigDict)
dict[c1.Id()] = c1
dict[c2.Id()] = c2
return dict
}

func TestAlfredSites_Encode(t *testing.T) {
dict := newAlfredConfigDict()
sites := &AlfredSites{}
json, err := sites.Encode(dict)
assert.OK(t, json != nil)
assert.OK(t, len(json) > 0)
assert.OK(t, err == nil)
}

func TestAlfredSites_Decode(t *testing.T) {
dict := newAlfredConfigDict()
sites := &AlfredSites{}
plist, _ := sites.Encode(dict)
data := bytes.NewReader(plist)
err := sites.Decode(data)
assert.OK(t, len(sites.CustomSites) == 2)
assert.OK(t, err == nil)
}

0 comments on commit 154e2b3

Please sign in to comment.