2016-12-28 01:45:11 +00:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
2016-01-19 23:09:19 +00:00
|
|
|
package updater
|
|
|
|
|
|
|
|
import (
|
2016-01-25 19:50:48 +00:00
|
|
|
"fmt"
|
2016-01-19 23:09:19 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-12-28 01:45:11 +00:00
|
|
|
|
|
|
|
"github.com/coreos/clair/database"
|
2016-01-19 23:09:19 +00:00
|
|
|
)
|
|
|
|
|
2016-01-25 19:50:48 +00:00
|
|
|
func TestDoVulnerabilitiesNamespacing(t *testing.T) {
|
2016-01-19 23:09:19 +00:00
|
|
|
fv1 := database.FeatureVersion{
|
|
|
|
Feature: database.Feature{
|
|
|
|
Namespace: database.Namespace{Name: "Namespace1"},
|
|
|
|
Name: "Feature1",
|
|
|
|
},
|
2016-12-28 01:45:11 +00:00
|
|
|
Version: "0.1",
|
2016-01-19 23:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fv2 := database.FeatureVersion{
|
|
|
|
Feature: database.Feature{
|
|
|
|
Namespace: database.Namespace{Name: "Namespace2"},
|
|
|
|
Name: "Feature1",
|
|
|
|
},
|
2016-12-28 01:45:11 +00:00
|
|
|
Version: "0.2",
|
2016-01-19 23:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fv3 := database.FeatureVersion{
|
|
|
|
Feature: database.Feature{
|
|
|
|
Namespace: database.Namespace{Name: "Namespace2"},
|
|
|
|
Name: "Feature2",
|
|
|
|
},
|
2016-12-28 01:45:11 +00:00
|
|
|
Version: "0.3",
|
2016-01-19 23:09:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vulnerability := database.Vulnerability{
|
|
|
|
Name: "DoVulnerabilityNamespacing",
|
|
|
|
FixedIn: []database.FeatureVersion{fv1, fv2, fv3},
|
|
|
|
}
|
|
|
|
|
2016-01-25 19:50:48 +00:00
|
|
|
vulnerabilities := doVulnerabilitiesNamespacing([]database.Vulnerability{vulnerability})
|
2016-01-19 23:09:19 +00:00
|
|
|
for _, vulnerability := range vulnerabilities {
|
|
|
|
switch vulnerability.Namespace.Name {
|
|
|
|
case fv1.Feature.Namespace.Name:
|
|
|
|
assert.Len(t, vulnerability.FixedIn, 1)
|
|
|
|
assert.Contains(t, vulnerability.FixedIn, fv1)
|
|
|
|
case fv2.Feature.Namespace.Name:
|
|
|
|
assert.Len(t, vulnerability.FixedIn, 2)
|
|
|
|
assert.Contains(t, vulnerability.FixedIn, fv2)
|
|
|
|
assert.Contains(t, vulnerability.FixedIn, fv3)
|
|
|
|
default:
|
|
|
|
t.Errorf("Should not have a Vulnerability with '%s' as its Namespace.", vulnerability.Namespace.Name)
|
2016-01-25 19:50:48 +00:00
|
|
|
fmt.Printf("%#v\n", vulnerability)
|
2016-01-19 23:09:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|