rename Identity() to ID()

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-11-09 17:23:48 -05:00
parent 52adfcbd44
commit 1537e73083
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
7 changed files with 13 additions and 13 deletions

View File

@ -71,7 +71,7 @@ func toPackageModel(p pkg.Package) model.Package {
return model.Package{
PackageBasicData: model.PackageBasicData{
ID: string(p.Identity()),
ID: string(p.ID()),
Name: p.Name,
Version: p.Version,
Type: p.Type,
@ -93,8 +93,8 @@ func toRelationshipModel(relationships []artifact.Relationship) []model.Relation
result := make([]model.Relationship, len(relationships))
for i, r := range relationships {
result[i] = model.Relationship{
Parent: string(r.From.Identity()),
Child: string(r.To.Identity()),
Parent: string(r.From.ID()),
Child: string(r.To.ID()),
Type: string(r.Type),
Metadata: r.Data,
}

View File

@ -4,5 +4,5 @@ package artifact
type ID string
type Identifiable interface {
Identity() ID
ID() ID
}

View File

@ -76,7 +76,7 @@ func (c *Catalog) Add(p Package) {
defer c.lock.Unlock()
// note: since we are capturing the ID, we cannot modify the package being added from this point forward
id := p.Identity()
id := p.ID()
// store by package ID
c.byID[id] = p

View File

@ -45,7 +45,7 @@ type expectedIndexes struct {
func TestCatalogAddPopulatesIndex(t *testing.T) {
fixtureID := func(i int) string {
return string(catalogAddAndRemoveTestPkgs[i].Identity())
return string(catalogAddAndRemoveTestPkgs[i].ID())
}
tests := []struct {
@ -91,7 +91,7 @@ func assertIndexes(t *testing.T, c *Catalog, expectedIndexes expectedIndexes) {
for path, expectedIds := range expectedIndexes.byPath {
actualIds := strset.New()
for _, p := range c.PackagesByPath(path) {
actualIds.Add(string(p.Identity()))
actualIds.Add(string(p.ID()))
}
if !expectedIds.IsEqual(actualIds) {
@ -106,7 +106,7 @@ func assertIndexes(t *testing.T, c *Catalog, expectedIndexes expectedIndexes) {
for ty, expectedIds := range expectedIndexes.byType {
actualIds := strset.New()
for p := range c.Enumerate(ty) {
actualIds.Add(string(p.Identity()))
actualIds.Add(string(p.ID()))
}
if !expectedIds.IsEqual(actualIds) {

View File

@ -51,7 +51,7 @@ func findOwnershipByFilesRelationships(catalog *Catalog) map[artifact.ID]map[art
}
for _, candidateOwnerPkg := range catalog.Sorted() {
id := candidateOwnerPkg.Identity()
id := candidateOwnerPkg.ID()
if candidateOwnerPkg.Metadata == nil {
continue
}
@ -70,7 +70,7 @@ func findOwnershipByFilesRelationships(catalog *Catalog) map[artifact.ID]map[art
// look for package(s) in the catalog that may be owned by this package and mark the relationship
for _, subPackage := range catalog.PackagesByPath(ownedFilePath) {
subID := subPackage.Identity()
subID := subPackage.ID()
if subID == id {
continue
}

View File

@ -172,8 +172,8 @@ func TestOwnershipByFilesRelationship(t *testing.T) {
assert.Len(t, relationships, len(expectedRelations))
for idx, expectedRelationship := range expectedRelations {
actualRelationship := relationships[idx]
assert.Equal(t, expectedRelationship.From.Identity(), actualRelationship.From.Identity())
assert.Equal(t, expectedRelationship.To.Identity(), actualRelationship.To.Identity())
assert.Equal(t, expectedRelationship.From.ID(), actualRelationship.From.ID())
assert.Equal(t, expectedRelationship.To.ID(), actualRelationship.To.ID())
assert.Equal(t, expectedRelationship.Type, actualRelationship.Type)
assert.Equal(t, expectedRelationship.Data, actualRelationship.Data)
}

View File

@ -29,7 +29,7 @@ type Package struct {
Metadata interface{} // additional data found while parsing the package source
}
func (p Package) Identity() artifact.ID {
func (p Package) ID() artifact.ID {
f, err := p.Fingerprint()
if err != nil {
// TODO: what to do in this case?