aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-22 21:03:24 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-22 21:03:24 -0500
commit86240375e87482836f5c5877f091df545895f547 (patch)
treebed6ac8a5c26b6f77b4b0007eb64a481b5eaf78d
parent8edac6d76d5359c06a86fd2f24a44956d6158c22 (diff)
downloadcvez-86240375e87482836f5c5877f091df545895f547.tar.bz2
cvez-86240375e87482836f5c5877f091df545895f547.zip
nvdmirror: add failsetcache
-rw-r--r--nvdmirror/failsetcache.go25
-rw-r--r--nvdmirror/failsetcache_test.go29
2 files changed, 54 insertions, 0 deletions
diff --git a/nvdmirror/failsetcache.go b/nvdmirror/failsetcache.go
new file mode 100644
index 0000000..ed5679b
--- /dev/null
+++ b/nvdmirror/failsetcache.go
@@ -0,0 +1,25 @@
+package nvdmirror
+
+import (
+ "fmt"
+)
+
+// Mock cache implementation that fails on Set().
+type FailSetCache byte
+
+// Get cache value. Always returns not found.
+func (me FailSetCache) Get(_ string) (map[string]string, bool) {
+ return nil, false
+}
+
+// Set cache value (fails unconditionally).
+func (me FailSetCache) Set(s string, _ map[string]string) error {
+ return fmt.Errorf("set failed: %s", s)
+}
+
+// Close cache. Always succeeds
+func (me FailSetCache) Close() error {
+ return nil
+}
+
+
diff --git a/nvdmirror/failsetcache_test.go b/nvdmirror/failsetcache_test.go
new file mode 100644
index 0000000..8e20a33
--- /dev/null
+++ b/nvdmirror/failsetcache_test.go
@@ -0,0 +1,29 @@
+package nvdmirror
+
+import "testing"
+
+func TestFailSetCache(t *testing.T) {
+ var data map[string]string
+ var cache FailSetCache
+
+ // test get
+ t.Run("Get", func(t *testing.T) {
+ if got, ok := cache.Get("foo"); ok {
+ t.Errorf("got %v, exp !ok", got)
+ }
+ })
+
+ // test set
+ t.Run("Set", func(t *testing.T) {
+ if err := cache.Set("bar", data); err == nil {
+ t.Errorf("got success, exp err")
+ }
+ })
+
+ // test Close
+ t.Run("Close", func(t *testing.T) {
+ if err := cache.Close(); err != nil {
+ t.Error(err)
+ }
+ })
+}