2016-05-02 22:33:29 +00:00
|
|
|
// Copyright 2015 clair authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package database
|
|
|
|
|
2018-09-07 20:12:19 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/coreos/clair/pkg/pagination"
|
|
|
|
)
|
2016-05-02 22:33:29 +00:00
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
// MockSession implements Session and enables overriding each available method.
|
2016-05-02 22:33:29 +00:00
|
|
|
// The default behavior of each method is to simply panic.
|
2017-07-26 23:22:29 +00:00
|
|
|
type MockSession struct {
|
|
|
|
FctCommit func() error
|
|
|
|
FctRollback func() error
|
2018-09-07 15:31:35 +00:00
|
|
|
FctUpsertAncestry func(Ancestry) error
|
2018-09-05 15:34:49 +00:00
|
|
|
FctFindAncestry func(name string) (Ancestry, bool, error)
|
2017-07-26 23:22:29 +00:00
|
|
|
FctFindAffectedNamespacedFeatures func(features []NamespacedFeature) ([]NullableAffectedNamespacedFeature, error)
|
|
|
|
FctPersistNamespaces func([]Namespace) error
|
|
|
|
FctPersistFeatures func([]Feature) error
|
|
|
|
FctPersistNamespacedFeatures func([]NamespacedFeature) error
|
|
|
|
FctCacheAffectedNamespacedFeatures func([]NamespacedFeature) error
|
2018-09-05 15:34:49 +00:00
|
|
|
FctPersistLayer func(hash string) error
|
2017-07-26 23:22:29 +00:00
|
|
|
FctPersistLayerContent func(hash string, namespaces []Namespace, features []Feature, processedBy Processors) error
|
2018-09-05 15:34:49 +00:00
|
|
|
FctFindLayer func(name string) (Layer, bool, error)
|
2017-07-26 23:22:29 +00:00
|
|
|
FctFindLayerWithContent func(name string) (LayerWithContent, bool, error)
|
|
|
|
FctInsertVulnerabilities func([]VulnerabilityWithAffected) error
|
|
|
|
FctFindVulnerabilities func([]VulnerabilityID) ([]NullableVulnerability, error)
|
|
|
|
FctDeleteVulnerabilities func([]VulnerabilityID) error
|
|
|
|
FctInsertVulnerabilityNotifications func([]VulnerabilityNotification) error
|
|
|
|
FctFindNewNotification func(lastNotified time.Time) (NotificationHook, bool, error)
|
2018-09-07 20:12:19 +00:00
|
|
|
FctFindVulnerabilityNotification func(name string, limit int, oldPage pagination.Token, newPage pagination.Token) (
|
2017-07-26 23:22:29 +00:00
|
|
|
vuln VulnerabilityNotificationWithVulnerable, ok bool, err error)
|
|
|
|
FctMarkNotificationNotified func(name string) error
|
2016-05-02 22:33:29 +00:00
|
|
|
FctDeleteNotification func(name string) error
|
2017-07-26 23:22:29 +00:00
|
|
|
FctUpdateKeyValue func(key, value string) error
|
|
|
|
FctFindKeyValue func(key string) (string, bool, error)
|
|
|
|
FctLock func(name string, owner string, duration time.Duration, renew bool) (bool, time.Time, error)
|
|
|
|
FctUnlock func(name, owner string) error
|
|
|
|
FctFindLock func(name string) (string, time.Time, bool, error)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) Commit() error {
|
|
|
|
if ms.FctCommit != nil {
|
|
|
|
return ms.FctCommit()
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) Rollback() error {
|
|
|
|
if ms.FctRollback != nil {
|
|
|
|
return ms.FctRollback()
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2018-09-07 15:31:35 +00:00
|
|
|
func (ms *MockSession) UpsertAncestry(ancestry Ancestry) error {
|
2017-07-26 23:22:29 +00:00
|
|
|
if ms.FctUpsertAncestry != nil {
|
2018-09-05 15:34:49 +00:00
|
|
|
return ms.FctUpsertAncestry(ancestry)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:34:49 +00:00
|
|
|
func (ms *MockSession) FindAncestry(name string) (Ancestry, bool, error) {
|
2017-07-26 23:22:29 +00:00
|
|
|
if ms.FctFindAncestry != nil {
|
|
|
|
return ms.FctFindAncestry(name)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) FindAffectedNamespacedFeatures(features []NamespacedFeature) ([]NullableAffectedNamespacedFeature, error) {
|
|
|
|
if ms.FctFindAffectedNamespacedFeatures != nil {
|
|
|
|
return ms.FctFindAffectedNamespacedFeatures(features)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) PersistNamespaces(namespaces []Namespace) error {
|
|
|
|
if ms.FctPersistNamespaces != nil {
|
|
|
|
return ms.FctPersistNamespaces(namespaces)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) PersistFeatures(features []Feature) error {
|
|
|
|
if ms.FctPersistFeatures != nil {
|
|
|
|
return ms.FctPersistFeatures(features)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) PersistNamespacedFeatures(namespacedFeatures []NamespacedFeature) error {
|
|
|
|
if ms.FctPersistNamespacedFeatures != nil {
|
|
|
|
return ms.FctPersistNamespacedFeatures(namespacedFeatures)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) CacheAffectedNamespacedFeatures(namespacedFeatures []NamespacedFeature) error {
|
|
|
|
if ms.FctCacheAffectedNamespacedFeatures != nil {
|
|
|
|
return ms.FctCacheAffectedNamespacedFeatures(namespacedFeatures)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:34:49 +00:00
|
|
|
func (ms *MockSession) PersistLayer(layer string) error {
|
2017-07-26 23:22:29 +00:00
|
|
|
if ms.FctPersistLayer != nil {
|
|
|
|
return ms.FctPersistLayer(layer)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) PersistLayerContent(hash string, namespaces []Namespace, features []Feature, processedBy Processors) error {
|
|
|
|
if ms.FctPersistLayerContent != nil {
|
|
|
|
return ms.FctPersistLayerContent(hash, namespaces, features, processedBy)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2018-09-05 15:34:49 +00:00
|
|
|
func (ms *MockSession) FindLayer(name string) (Layer, bool, error) {
|
2017-07-26 23:22:29 +00:00
|
|
|
if ms.FctFindLayer != nil {
|
|
|
|
return ms.FctFindLayer(name)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) FindLayerWithContent(name string) (LayerWithContent, bool, error) {
|
|
|
|
if ms.FctFindLayerWithContent != nil {
|
|
|
|
return ms.FctFindLayerWithContent(name)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
2017-07-26 23:22:29 +00:00
|
|
|
|
|
|
|
func (ms *MockSession) InsertVulnerabilities(vulnerabilities []VulnerabilityWithAffected) error {
|
|
|
|
if ms.FctInsertVulnerabilities != nil {
|
|
|
|
return ms.FctInsertVulnerabilities(vulnerabilities)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) FindVulnerabilities(vulnerabilityIDs []VulnerabilityID) ([]NullableVulnerability, error) {
|
|
|
|
if ms.FctFindVulnerabilities != nil {
|
|
|
|
return ms.FctFindVulnerabilities(vulnerabilityIDs)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) DeleteVulnerabilities(VulnerabilityIDs []VulnerabilityID) error {
|
|
|
|
if ms.FctDeleteVulnerabilities != nil {
|
|
|
|
return ms.FctDeleteVulnerabilities(VulnerabilityIDs)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) InsertVulnerabilityNotifications(vulnerabilityNotifications []VulnerabilityNotification) error {
|
|
|
|
if ms.FctInsertVulnerabilityNotifications != nil {
|
|
|
|
return ms.FctInsertVulnerabilityNotifications(vulnerabilityNotifications)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) FindNewNotification(lastNotified time.Time) (NotificationHook, bool, error) {
|
|
|
|
if ms.FctFindNewNotification != nil {
|
|
|
|
return ms.FctFindNewNotification(lastNotified)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2018-09-07 20:12:19 +00:00
|
|
|
func (ms *MockSession) FindVulnerabilityNotification(name string, limit int, oldPage pagination.Token, newPage pagination.Token) (
|
2017-07-26 23:22:29 +00:00
|
|
|
VulnerabilityNotificationWithVulnerable, bool, error) {
|
|
|
|
if ms.FctFindVulnerabilityNotification != nil {
|
|
|
|
return ms.FctFindVulnerabilityNotification(name, limit, oldPage, newPage)
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:22:29 +00:00
|
|
|
func (ms *MockSession) MarkNotificationNotified(name string) error {
|
|
|
|
if ms.FctMarkNotificationNotified != nil {
|
|
|
|
return ms.FctMarkNotificationNotified(name)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) DeleteNotification(name string) error {
|
|
|
|
if ms.FctDeleteNotification != nil {
|
|
|
|
return ms.FctDeleteNotification(name)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) UpdateKeyValue(key, value string) error {
|
|
|
|
if ms.FctUpdateKeyValue != nil {
|
|
|
|
return ms.FctUpdateKeyValue(key, value)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) FindKeyValue(key string) (string, bool, error) {
|
|
|
|
if ms.FctFindKeyValue != nil {
|
|
|
|
return ms.FctFindKeyValue(key)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) Lock(name string, owner string, duration time.Duration, renew bool) (bool, time.Time, error) {
|
|
|
|
if ms.FctLock != nil {
|
|
|
|
return ms.FctLock(name, owner, duration, renew)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) Unlock(name, owner string) error {
|
|
|
|
if ms.FctUnlock != nil {
|
|
|
|
return ms.FctUnlock(name, owner)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ms *MockSession) FindLock(name string) (string, time.Time, bool, error) {
|
|
|
|
if ms.FctFindLock != nil {
|
|
|
|
return ms.FctFindLock(name)
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// MockDatastore implements Datastore and enables overriding each available method.
|
|
|
|
// The default behavior of each method is to simply panic.
|
|
|
|
type MockDatastore struct {
|
|
|
|
FctBegin func() (Session, error)
|
|
|
|
FctPing func() bool
|
|
|
|
FctClose func()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mds *MockDatastore) Begin() (Session, error) {
|
|
|
|
if mds.FctBegin != nil {
|
|
|
|
return mds.FctBegin()
|
2016-05-02 22:33:29 +00:00
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mds *MockDatastore) Ping() bool {
|
|
|
|
if mds.FctPing != nil {
|
|
|
|
return mds.FctPing()
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mds *MockDatastore) Close() {
|
|
|
|
if mds.FctClose != nil {
|
|
|
|
mds.FctClose()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
panic("required mock function not implemented")
|
|
|
|
}
|