featurens: added multiple namespace testing for namespace detector
This commit is contained in:
parent
bffa6499b7
commit
75d5d40d79
10
database/pgsql/testdata/data.sql
vendored
10
database/pgsql/testdata/data.sql
vendored
@ -36,11 +36,11 @@ INSERT INTO layer (id, name, engineversion, parent_id) VALUES
|
|||||||
(5, 'layer-3b', 1, 3);
|
(5, 'layer-3b', 1, 3);
|
||||||
|
|
||||||
INSERT INTO layer_namespace (id, layer_id, namespace_id) VALUES
|
INSERT INTO layer_namespace (id, layer_id, namespace_id) VALUES
|
||||||
(1, 2, 1),
|
(1, 2, 1),
|
||||||
(2, 3, 1),
|
(2, 3, 1),
|
||||||
(3, 4, 1),
|
(3, 4, 1),
|
||||||
(4, 5, 2),
|
(4, 5, 2),
|
||||||
(5, 5, 1);
|
(5, 5, 1);
|
||||||
|
|
||||||
INSERT INTO layer_diff_featureversion (id, layer_id, featureversion_id, modification) VALUES
|
INSERT INTO layer_diff_featureversion (id, layer_id, featureversion_id, modification) VALUES
|
||||||
(1, 2, 1, 'add'),
|
(1, 2, 1, 'add'),
|
||||||
|
66
ext/featurens/driver_test.go
Normal file
66
ext/featurens/driver_test.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package featurens_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/coreos/clair/database"
|
||||||
|
"github.com/coreos/clair/ext/featurens"
|
||||||
|
"github.com/coreos/clair/pkg/tarutil"
|
||||||
|
|
||||||
|
_ "github.com/coreos/clair/ext/featurens/alpinerelease"
|
||||||
|
_ "github.com/coreos/clair/ext/featurens/aptsources"
|
||||||
|
_ "github.com/coreos/clair/ext/featurens/lsbrelease"
|
||||||
|
_ "github.com/coreos/clair/ext/featurens/osrelease"
|
||||||
|
_ "github.com/coreos/clair/ext/featurens/redhatrelease"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MultipleNamespaceTestData struct {
|
||||||
|
Files tarutil.FilesMap
|
||||||
|
ExpectedNamespaces []database.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertnsNameEqual(t *testing.T, nslist_expected, nslist []database.Namespace) {
|
||||||
|
assert.Equal(t, len(nslist_expected), len(nslist))
|
||||||
|
expected := map[string]struct{}{}
|
||||||
|
input := map[string]struct{}{}
|
||||||
|
// compare the two sets
|
||||||
|
for i := range nslist_expected {
|
||||||
|
expected[nslist_expected[i].Name] = struct{}{}
|
||||||
|
input[nslist[i].Name] = struct{}{}
|
||||||
|
}
|
||||||
|
assert.Equal(t, expected, input)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testMultipleNamespace(t *testing.T, testData []MultipleNamespaceTestData) {
|
||||||
|
for _, td := range testData {
|
||||||
|
nslist, err := featurens.Detect(td.Files)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assertnsNameEqual(t, td.ExpectedNamespaces, nslist)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMultipleNamespaceDetector(t *testing.T) {
|
||||||
|
testData := []MultipleNamespaceTestData{
|
||||||
|
{
|
||||||
|
ExpectedNamespaces: []database.Namespace{
|
||||||
|
database.Namespace{Name: "debian:8", VersionFormat: "dpkg"},
|
||||||
|
database.Namespace{Name: "alpine:v3.3", VersionFormat: "dpkg"},
|
||||||
|
},
|
||||||
|
Files: tarutil.FilesMap{
|
||||||
|
"etc/os-release": []byte(`
|
||||||
|
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
|
||||||
|
NAME="Debian GNU/Linux"
|
||||||
|
VERSION_ID="8"
|
||||||
|
VERSION="8 (jessie)"
|
||||||
|
ID=debian
|
||||||
|
HOME_URL="http://www.debian.org/"
|
||||||
|
SUPPORT_URL="http://www.debian.org/support/"
|
||||||
|
BUG_REPORT_URL="https://bugs.debian.org/"`),
|
||||||
|
"etc/alpine-release": []byte(`3.3.4`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
testMultipleNamespace(t, testData)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user