-
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.
Merge pull request #1 from Jisin0:tests
Create Tests for cache & encode
- Loading branch information
Showing
3 changed files
with
107 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,45 @@ | ||
package cache_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/Jisin0/filmigo/cache" | ||
) | ||
|
||
func TestCache(t *testing.T) { | ||
directoryName := "testcache" | ||
c := cache.NewCache(directoryName, 1*time.Hour) | ||
|
||
type sampleType struct { | ||
String string `json:"string"` | ||
Integer int `json:"int"` | ||
} | ||
|
||
inputData := sampleType{ | ||
String: "foo", | ||
Integer: 3, | ||
} | ||
|
||
err := c.Save("uid", inputData) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
var outputData sampleType | ||
|
||
err = c.Load("uid", &outputData) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if outputData != inputData { | ||
t.Logf("Input: %+v\nOutput: %+v", inputData, outputData) | ||
} | ||
|
||
err = os.RemoveAll(directoryName) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
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,25 @@ | ||
<html> | ||
<body> | ||
<main> | ||
<ul class="sample"> | ||
<li>Node 1</li> | ||
<li>Node 2</li> | ||
<li>Node 3</li> | ||
</ul> | ||
|
||
<span class="sample"> | ||
<a href="example.com">Data 1</a> | ||
<a href="example.com">Data 2</a> | ||
<span class="subnode"> | ||
<a href="example.com">Data 3</a> | ||
</span> | ||
</span> | ||
|
||
<p class="find-substring-here"> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non tortor in orci sagittis vehicula accumsan vel magna. Fusce et nulla nec eros egestas ullamcorper. Phasellus consequat euismod efficitur. Fusce nec bibendum diam, eu mollis turpis. Sed nisi tellus, euismod ut viverra vitae, efficitur et magna. Proin dictum tellus ac augue semper, quis pharetra mauris ullamcorper. Duis quis ullamcorper metus. Morbi eu leo et augue aliquam faucibus. | ||
</p> | ||
|
||
<p my-attr="sample"></p> | ||
</main> | ||
</body> | ||
</html> |
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,37 @@ | ||
package encode_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Jisin0/filmigo/encode" | ||
"github.com/Jisin0/filmigo/types" | ||
"github.com/antchfx/htmlquery" | ||
) | ||
|
||
func TestXpath(t *testing.T) { | ||
doc, err := htmlquery.LoadDoc("sample.html") | ||
if err != nil { | ||
t.Errorf("failed to open sample file : %v", err) | ||
t.FailNow() | ||
} | ||
|
||
if doc != nil { | ||
type sampleData struct { | ||
InnerText string `xpath:"//p[contains(@class, 'substring')]"` | ||
Attribute string `xpath:"//p[last()]|attr_my-attr"` | ||
LinkList types.Links `xpath:"//span[@class='sample']"` | ||
StringList []string `xpath:"//ul"` | ||
} | ||
|
||
res, ok := encode.Xpath(doc, sampleData{}).(sampleData) | ||
if !ok { | ||
t.Errorf("unknown type returned") | ||
t.FailNow() | ||
} | ||
|
||
if res.Attribute == "" || res.InnerText == "" || len(res.LinkList) < 3 || len(res.StringList) < 3 { | ||
t.Errorf("xpath failed with output : %+v", res) | ||
t.FailNow() | ||
} | ||
} | ||
} |