-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
featurens: added multiple namespace testing for namespace detector
- Loading branch information
1 parent
ca76565
commit 2b56d6a
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package featurens_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/coreos/clair/database" | ||
"github.com/coreos/clair/ext/featurens" | ||
_ "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" | ||
"github.com/coreos/clair/pkg/tarutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
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) | ||
} |