clair: github.com/coreos/clair/database/pgsql/testutil Index | Files

package testutil

import "github.com/coreos/clair/database/pgsql/testutil"

Index

Package Files

assertion.go data.go testdb.go testutil.go

Variables

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.

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

func AssertAffectedFeaturesEqual Uses

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

func AssertNamespacedFeatureEqual Uses

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

func AssertPagedVulnerableAncestriesEqual Uses

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

func AssertVulnerabilityNotificationWithVulnerableEqual Uses

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

func AssertVulnerabilityWithAffectedEqual Uses

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

func CreateAndConnectTestDB Uses

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

func CreateTestDB Uses

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

func CreateTestDBWithFixture Uses

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

func CreateTestTx Uses

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

func CreateTestTxWithFixtures Uses

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

func GenRandomNamespaces Uses

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

func ListNamespaces Uses

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

func MustMarshalToken Uses

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

func OpenSessionForTest Uses

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

func RestartTransaction Uses

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

func TakeAncestryPointerFromMap Uses

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

func TakeLayerPointerFromMap Uses

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

Package testutil imports 16 packages (graph). Updated 2019-03-14. Refresh now. Tools for package owners.