Skip to content

Commit

Permalink
updated unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
batorfc committed Dec 5, 2019
1 parent ea54e7d commit c90022f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/devmatic-it/debcvescan

go 1.13

require pault.ag/go/debian v0.0.0-20190530135403-b831f604d664
require (
gopkg.in/h2non/gock.v1 v1.0.15
pault.ag/go/debian v0.0.0-20190530135403-b831f604d664
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/kjk/lzma v0.0.0-20161016003348-3fd93898850d/go.mod h1:phT/jsRPBAEqjAibu1BurrabCBNTYiVI+zbmyCZJY6Q=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
pault.ag/go/debian v0.0.0-20190530135403-b831f604d664 h1:GDl2DtfgRo7vwwoJifnkaG97iy0JnOFqxi+qePf+1nk=
pault.ag/go/debian v0.0.0-20190530135403-b831f604d664/go.mod h1:e7Gva9AMoKtUKYJ1G9kIesbh+4VS2JnAOS8VWafyTCk=
pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a/go.mod h1:INqx0ClF7kmPAMk2zVTX8DRnhZ/yaA/Mg52g8KFKE7k=
35 changes: 35 additions & 0 deletions pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,43 @@ import (
"testing"

"github.com/devmatic-it/debcvescan/pkg/dpkg"
"gopkg.in/h2non/gock.v1"
)

func TestScanPackages(t *testing.T) {
packages := dpkg.LoadInstalledPackages("../../data/dpkg/status")
if packages == nil {
t.Fail()
}

file, err := os.Open("../../data/json.json")
if err != nil {
t.Fail()
}

defer gock.Off()
gock.New("https://security-tracker.debian.org").
Get("/tracker/data/json").Reply(200).Body(file)

vulnerabilties := ScanPackages(packages)
if vulnerabilties == nil {
t.Fail()
}

if len(vulnerabilties) == 0 {
t.Fail()
}

vul := vulnerabilties[0]
if vul.PackageName == "" {
t.Errorf("Expected package name, but found %s", vul.PackageName)
}

if !gock.IsDone() {
t.Fail()
}
}

func TestScanPackagesFromReader(t *testing.T) {
packages := dpkg.LoadInstalledPackages("../../data/dpkg/status")
if packages == nil {
Expand Down

0 comments on commit c90022f

Please sign in to comment.