newsbot-api/services/cache_test.go
James Tombleson eba63c27ef
Youtube source is now working (#5)
* added extra packages to help with parsing

* getting the core built for Youtube collection.  The feed can be pulled and starting to build the article object

* added some tests, reddit will need more love but youtube is starting off with more tests.  Starting to add Rod to pull missing values from the site

* Added rod to work with browser automation

* Moved the config inside the client as they can change within runtime and need to be refreshed on each client creation

* added more features to collect data per video and tests to support them.

* adding the cache and tests

* moved errors to var values at the top

* youtube is now getting collected and tests have been setup

* resolved an issue with the config

* setting up the first interface, its not used yet

* more updates to the cache service. Not finished yet and could see rework

* added logic to monitor Youtube.  Still basic logic that needs to be wired up to the database
2022-04-17 07:25:49 -07:00

69 lines
1.5 KiB
Go

package services_test
import (
"testing"
"time"
"github.com/jtom38/newsbot/collector/domain/model"
"github.com/jtom38/newsbot/collector/services"
)
func TestNewCacheClient(t *testing.T) {
_ = services.NewCacheClient()
}
func TestInsert(t *testing.T) {
cache := services.NewCacheClient()
var item *model.CacheItem = &model.CacheItem{
Key: "UnitTesting",
Value: "Something, or nothing",
Group: "Testing",
Expires: time.Now().Add(5 * time.Second),
}
cache.Insert(item)
}
func TestFindGroupMissing(t *testing.T) {
cache := services.NewCacheClient()
_, err := cache.Find("UnitTesting", "Unknown")
if err == nil { panic("Nothing was appended with the requested group.") }
}
func TestFindGroupExists(t *testing.T) {
cache := services.NewCacheClient()
var item *model.CacheItem = &model.CacheItem{
Key: "UnitTesting",
Value: "Something, or nothing",
Group: "Testing",
Expires: time.Now().Add(5 * time.Second),
}
cache.Insert(item)
_, err := cache.Find("UnitTesting", "Testing2")
//t.Log(res)
if err == nil { panic("") }
}
func TestCacheStorage(t *testing.T) {
cc := services.NewCacheClient()
item1 := &model.CacheItem {
Key: "UnitTesting01",
Value: "",
Group: "Testing",
Expires: time.Now().Add(5 * time.Minute),
}
cc.Insert(item1)
item2 := &model.CacheItem {
Key: "UnitTesting02",
Value: "",
Group: "Testing",
Expires: time.Now().Add(5 * time.Minute),
}
cc.Insert(item2)
cache := services.NewCacheClient()
_, err := cache.Find("UnitTesting02", "Testing")
if err != nil { panic("expected to find the value")}
}