aboutsummaryrefslogtreecommitdiff
path: root/dbstore/util_test.go
blob: a949878630a1eab822b545f483613fa71b859fce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package dbstore

import (
  "github.com/pablotron/cvez/feed"
  "testing"
)

func TestCheckNvdData(t *testing.T) {
  passTests := []struct {
    name string
    dt feed.DataType
    df feed.DataFormat
    dv feed.DataVersion
  } {
    { "valid", feed.CveType, feed.MitreFormat, feed.V40 },
  }

  for _, test := range(passTests) {
    t.Run(test.name, func(t *testing.T) {
      if err := checkNvdData(test.dt, test.df, test.dv); err != nil {
        t.Error(err)
      }
    })
  }

  failTests := []struct {
    name string
    dt feed.DataType
    df feed.DataFormat
    dv feed.DataVersion
  } {
    { "bad type", feed.DataType(255), feed.MitreFormat, feed.V40 },
    { "bad format", feed.CveType, feed.DataFormat(255), feed.V40 },
    { "bad version", feed.CveType, feed.MitreFormat, feed.DataVersion(255) },
  }

  for _, test := range(failTests) {
    t.Run(test.name, func(t *testing.T) {
      if checkNvdData(test.dt, test.df, test.dv) == nil {
        t.Errorf("got success, exp error")
      }
    })
  }
}