testutil

package
v3.0.0-pre1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RealFeatures = map[int]database.Feature{
		1: {"ourchat", "0.5", "dpkg", "source"},
		2: {"openssl", "1.0", "dpkg", "source"},
		3: {"openssl", "2.0", "dpkg", "source"},
		4: {"fake", "2.0", "rpm", "source"},
		5: {"mount", "2.31.1-0.4ubuntu3.1", "dpkg", "binary"},
	}

	RealNamespaces = map[int]database.Namespace{
		1: {"debian:7", "dpkg"},
		2: {"debian:8", "dpkg"},
		3: {"fake:1.0", "rpm"},
		4: {"cpe:/o:redhat:enterprise_linux:7::server", "rpm"},
	}

	RealNamespacedFeatures = map[int]database.NamespacedFeature{
		1: {RealFeatures[1], RealNamespaces[1]},
		2: {RealFeatures[2], RealNamespaces[1]},
		3: {RealFeatures[2], RealNamespaces[2]},
		4: {RealFeatures[3], RealNamespaces[1]},
	}

	RealDetectors = map[int]database.Detector{
		1: database.NewNamespaceDetector("os-release", "1.0"),
		2: database.NewFeatureDetector("dpkg", "1.0"),
		3: database.NewFeatureDetector("rpm", "1.0"),
		4: database.NewNamespaceDetector("apt-sources", "1.0"),
	}

	RealLayers = map[int]database.Layer{
		2: {
			Hash: "layer-1",
			By:   []database.Detector{RealDetectors[1], RealDetectors[2]},
			Features: []database.LayerFeature{
				{RealFeatures[1], RealDetectors[2], database.Namespace{}},
				{RealFeatures[2], RealDetectors[2], database.Namespace{}},
			},
			Namespaces: []database.LayerNamespace{
				{RealNamespaces[1], RealDetectors[1]},
			},
		},
		6: {
			Hash: "layer-4",
			By:   []database.Detector{RealDetectors[1], RealDetectors[2], RealDetectors[3], RealDetectors[4]},
			Features: []database.LayerFeature{
				{RealFeatures[4], RealDetectors[3], database.Namespace{}},
				{RealFeatures[3], RealDetectors[2], database.Namespace{}},
			},
			Namespaces: []database.LayerNamespace{
				{RealNamespaces[1], RealDetectors[1]},
				{RealNamespaces[3], RealDetectors[4]},
			},
		},
	}

	RealAncestries = map[int]database.Ancestry{
		2: {
			Name: "ancestry-2",
			By:   []database.Detector{RealDetectors[2], RealDetectors[1]},
			Layers: []database.AncestryLayer{
				{
					"layer-0",
					[]database.AncestryFeature{},
				},
				{
					"layer-1",
					[]database.AncestryFeature{},
				},
				{
					"layer-2",
					[]database.AncestryFeature{
						{
							RealNamespacedFeatures[1],
							RealDetectors[2],
							RealDetectors[1],
						},
					},
				},
				{
					"layer-3b",
					[]database.AncestryFeature{
						{
							RealNamespacedFeatures[3],
							RealDetectors[2],
							RealDetectors[1],
						},
					},
				},
			},
		},
	}

	RealVulnerability = map[int]database.Vulnerability{
		1: {
			Name:        "CVE-OPENSSL-1-DEB7",
			Namespace:   RealNamespaces[1],
			Description: "A vulnerability affecting OpenSSL < 2.0 on Debian 7.0",
			Link:        "http://google.com/#q=CVE-OPENSSL-1-DEB7",
			Severity:    database.HighSeverity,
		},
		2: {
			Name:        "CVE-NOPE",
			Namespace:   RealNamespaces[1],
			Description: "A vulnerability affecting nothing",
			Severity:    database.UnknownSeverity,
		},
	}

	RealNotification = map[int]database.VulnerabilityNotification{
		1: {
			NotificationHook: database.NotificationHook{
				Name: "test",
			},
			Old: takeVulnerabilityPointerFromMap(RealVulnerability, 2),
			New: takeVulnerabilityPointerFromMap(RealVulnerability, 1),
		},
	}

	FakeFeatures = map[int]database.Feature{
		1: {
			Name:          "ourchat",
			Version:       "0.6",
			VersionFormat: "dpkg",
			Type:          "source",
		},
	}

	FakeNamespaces = map[int]database.Namespace{
		1: {"green hat", "rpm"},
	}

	FakeNamespacedFeatures = map[int]database.NamespacedFeature{
		1: {
			Feature:   FakeFeatures[0],
			Namespace: RealNamespaces[0],
		},
	}

	FakeDetector = map[int]database.Detector{
		1: {
			Name:    "fake",
			Version: "1.0",
			DType:   database.FeatureDetectorType,
		},
		2: {
			Name:    "fake2",
			Version: "2.0",
			DType:   database.NamespaceDetectorType,
		},
	}
)

int keys must be the consistent with the database ID.

View Source
var TestPaginationKey = pagination.Must(pagination.NewKey())

Functions

func AssertAffectedFeaturesEqual

func AssertAffectedFeaturesEqual(t *testing.T, expected []database.AffectedFeature, actual []database.AffectedFeature) bool

func AssertNamespacedFeatureEqual

func AssertNamespacedFeatureEqual(t *testing.T, expected []database.NamespacedFeature, actual []database.NamespacedFeature) bool

func AssertPagedVulnerableAncestriesEqual

func AssertPagedVulnerableAncestriesEqual(t *testing.T, key pagination.Key, expected, actual *database.PagedVulnerableAncestries) bool

func AssertVulnerabilityNotificationWithVulnerableEqual

func AssertVulnerabilityNotificationWithVulnerableEqual(t *testing.T, key pagination.Key, expected, actual *database.VulnerabilityNotificationWithVulnerable) bool

func AssertVulnerabilityWithAffectedEqual

func AssertVulnerabilityWithAffectedEqual(t *testing.T, expected database.VulnerabilityWithAffected, actual database.VulnerabilityWithAffected) bool

func CreateAndConnectTestDB

func CreateAndConnectTestDB(t *testing.T, testName string) (*sql.DB, func())

func CreateTestDB

func CreateTestDB(t *testing.T, testName string) (*sql.DB, func())

func CreateTestDBWithFixture

func CreateTestDBWithFixture(t *testing.T, testName string) (*sql.DB, func())

func CreateTestTx

func CreateTestTx(t *testing.T, testName string) (*sql.Tx, func())

func CreateTestTxWithFixtures

func CreateTestTxWithFixtures(t *testing.T, testName string) (*sql.Tx, func())

func GenRandomNamespaces

func GenRandomNamespaces(t *testing.T, count int) []database.Namespace

func ListNamespaces

func ListNamespaces(t *testing.T, tx *sql.Tx) []database.Namespace

func MustMarshalToken

func MustMarshalToken(key pagination.Key, v interface{}) pagination.Token

func OpenSessionForTest

func OpenSessionForTest(t *testing.T, name string, loadFixture bool) (*sql.DB, *sql.Tx)

func RestartTransaction

func RestartTransaction(db *sql.DB, tx *sql.Tx, commit bool) *sql.Tx

func TakeAncestryPointerFromMap

func TakeAncestryPointerFromMap(m map[int]database.Ancestry, id int) *database.Ancestry

func TakeLayerPointerFromMap

func TakeLayerPointerFromMap(m map[int]database.Layer, id int) *database.Layer

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL