-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for Sites' Encode/Decode
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |