aboutsummaryrefslogtreecommitdiff
path: root/internal/feed/vector_test.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-02 01:54:19 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-02 01:54:19 -0500
commit1b9eb2eddf322560c37efa2ef2eb63d5ab661be8 (patch)
treec3701545ed3a06bd31b197fa6155597d3674ffbf /internal/feed/vector_test.go
parent7d55dd69e3a481fa9885c5fe922c1606bbd928f4 (diff)
downloadcvez-1b9eb2eddf322560c37efa2ef2eb63d5ab661be8.tar.bz2
cvez-1b9eb2eddf322560c37efa2ef2eb63d5ab661be8.zip
internal/feed: add Vector#MarshalJSON and tests
Diffstat (limited to 'internal/feed/vector_test.go')
-rw-r--r--internal/feed/vector_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/feed/vector_test.go b/internal/feed/vector_test.go
index e956884..5dee8ba 100644
--- a/internal/feed/vector_test.go
+++ b/internal/feed/vector_test.go
@@ -2,6 +2,7 @@ package feed
import (
"encoding/json"
+ "nvd/internal/cvss"
"testing"
)
@@ -61,3 +62,38 @@ func TestVectorUnmarshalJSON(t *testing.T) {
})
}
}
+
+func TestVectorMarshalJSON(t *testing.T) {
+ tests := []string {
+ "AV:N/AC:M/Au:S/C:P/I:P/A:P",
+ "CVSS:3.0/AV:A/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:H",
+ "CVSS:3.1/AV:A/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H",
+ }
+
+ for _, val := range(tests) {
+ t.Run(val, func(t *testing.T) {
+ // get expected string
+ exp := "\"" + val + "\""
+
+ // create inner vector
+ vec, err := cvss.NewVector(val)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // serialize as json
+ buf, err := json.Marshal(Vector { vec })
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // check result
+ got := string(buf)
+ if got != exp {
+ t.Errorf("got \"%s\", exp \"%s\"", got, exp)
+ }
+ })
+ }
+}