Files

24 lines
848 B
Go

package main
import "testing"
func TestVulnDBUpdatedAt(t *testing.T) {
cases := []struct{ name, in, want string }{
{
"trivy version --format json",
`{"Version":"0.76.1","VulnerabilityDB":{"Version":2,"NextUpdate":"2026-11-04T12:00:00Z","UpdatedAt":"2026-11-04T06:00:00.5Z","DownloadedAt":"2026-11-04T07:00:00Z"},"JavaDB":{"Version":1,"UpdatedAt":"2020-01-01T00:00:00Z"}}`,
"2026-11-04T06:00:00.5Z",
},
// The Java DB's date is not the vulnerability DB's: never borrow it.
{"only the java db", `{"Version":"0.76.1","JavaDB":{"UpdatedAt":"2026-11-04T06:00:00Z"}}`, ""},
{"no db in the cache", `{"Version":"0.76.1"}`, ""},
{"not json", `Version: 0.76.1`, ""},
{"empty", ``, ""},
}
for _, c := range cases {
if got := vulnDBUpdatedAt(c.in); got != c.want {
t.Errorf("%s: got %q, want %q", c.name, got, c.want)
}
}
}