Skip to content

Commit

Permalink
add comps groups searching (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
rverdile authored Jan 22, 2024
1 parent e191e0e commit cf719bd
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 57 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ defer t.Close()

// Use Tangy to search for RPMs, by name, that are associated to a specific repository version, returning up to the first 100 results
versionHref := "/pulp/e1c6bee3/api/v3/repositories/rpm/rpm/018c1c95-4281-76eb-b277-842cbad524f4/versions/1/"
rows, err := t.RpmRepositoryVersionPackageSearch(context.Background(), []string{versionHref}, "ninja", 100)
rows, err := t.RpmRepositoryVersionPackageSearch(context.Background(), []string{versionHref}, "bear", 100)
if err != nil {
return err
}

// Use Tangy to search for RPM Package Groups, by name, that are associated to a specific repository version, returning up to the first 100 results
versionHref := "/pulp/e1c6bee3/api/v3/repositories/rpm/rpm/018c1c95-4281-76eb-b277-842cbad524f4/versions/1/"
rows, err := t.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{versionHref}, "mammals", 100)
if err != nil {
return err
}

// Use Tangy to search for RPM Environments, by name, that are associated to a specific repository version, returning up to the first 100 results
versionHref := "/pulp/e1c6bee3/api/v3/repositories/rpm/rpm/018c1c95-4281-76eb-b277-842cbad524f4/versions/1/"
rows, err := t.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{versionHref}, "animals", 100)
if err != nil {
return err
}
Expand Down
37 changes: 33 additions & 4 deletions example.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,45 @@ func main() {
}

// Use Tangy to search for RPMs, by name, that are associated to a specific repository version, returning up to the first 100 results
rows, err := t.RpmRepositoryVersionPackageSearch(context.Background(), []string{versionHref}, "ninja", 100)
rows, err := t.RpmRepositoryVersionPackageSearch(context.Background(), []string{versionHref}, "bear", 100)
if err != nil {
fmt.Println(err)
return
}

fmt.Printf("\nPackages\n==================\n")
for _, row := range rows {
fmt.Printf("\nName: %v \nSummary: %v", row.Name, row.Summary)
}
fmt.Printf("\n")

// Use Tangy to search for RPM package groups, by name, that are associated to a specific repository version, returning up to the first 100 results
var pkgGroups []tangy.RpmPackageGroupSearch
pkgGroups, err = t.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{versionHref}, "bir", 100)
if err != nil {
fmt.Println(err)
return
}

fmt.Printf("\nPackage Groups\n==================\n")
for _, row := range pkgGroups {
fmt.Printf("\nName: %v \nID: %v", row.Name, row.ID)
}
fmt.Printf("\n")

// Use Tangy to search for RPM environments, by name, that are associated to a specific repository version, returning up to the first 100 results
var pkgEnvs []tangy.RpmEnvironmentSearch
pkgEnvs, err = t.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{versionHref}, "avi", 100)
if err != nil {
fmt.Println(err)
return
}

fmt.Printf("\nEnvironments\n==================\n")
for _, row := range pkgEnvs {
fmt.Printf("\nName: %v \nID: %v", row.Name, row.ID)
}
fmt.Printf("\n")
}

func CreateRepositoryVersion() (versionHref string, err error) {
Expand All @@ -59,15 +88,15 @@ func CreateRepositoryVersion() (versionHref string, err error) {
DownloadPolicy: "on_demand",
})

domainName := "example-domain"
domainName := "example-domain-12231231"

// Create domain and repository, then sync repository, to create a new repository version with rpm packages
_, err = rpmZest.LookupOrCreateDomain(domainName)
if err != nil {
return "", err
}

repoHref, remoteHref, err := rpmZest.CreateRepository(domainName, "rpm modular", "https://fixtures.pulpproject.org/rpm-modular/")
repoHref, remoteHref, err := rpmZest.CreateRepository(domainName, "zoo", "https://rverdile.fedorapeople.org/dummy-repos/comps/repo2/")
if err != nil {
return "", err
}
Expand All @@ -82,7 +111,7 @@ func CreateRepositoryVersion() (versionHref string, err error) {
return "", err
}

resp, err := rpmZest.GetRpmRepositoryByName(domainName, "rpm modular")
resp, err := rpmZest.GetRpmRepositoryByName(domainName, "zoo")
if err != nil {
return "", err
}
Expand Down
180 changes: 137 additions & 43 deletions internal/test/integration/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import (

type RpmSuite struct {
suite.Suite
client *zestwrapper.RpmZest
tangy tangy.Tangy
domainName string
remoteHref string
repoHref string
client *zestwrapper.RpmZest
tangy tangy.Tangy
domainName string
remoteHref string
repoHref string
firstVersionHref string
secondVersionHref string
}

const testRepoName = "rpm modular"
const testRepoURL = "https://jlsherrill.fedorapeople.org/fake-repos/revision/one/"
const testRepoURLTwo = "https://jlsherrill.fedorapeople.org/fake-repos/revision/two/"
const testRepoName = "zoo"
const testRepoURL = "https://rverdile.fedorapeople.org/dummy-repos/comps/repo1/"
const testRepoURLTwo = "https://rverdile.fedorapeople.org/dummy-repos/comps/repo2/"

func (r *RpmSuite) CreateTestRepository(t *testing.T) {
domainName := RandStringBytes(10)
Expand Down Expand Up @@ -77,75 +79,167 @@ func TestRpmSuite(t *testing.T) {
r.client = &rpmZest
r.tangy = ta
r.CreateTestRepository(t)

// Get first version href
resp, err := r.client.GetRpmRepositoryByName(r.domainName, testRepoName)
require.NoError(t, err)
require.NotNil(t, resp.LatestVersionHref)
r.firstVersionHref = *resp.LatestVersionHref

// Create second repository version
r.UpdateTestRepository(t, testRepoURLTwo)
resp, err = r.client.GetRpmRepositoryByName(r.domainName, testRepoName)
require.NoError(t, err)
require.NotNil(t, resp.LatestVersionHref)
r.secondVersionHref = *resp.LatestVersionHref

suite.Run(t, &r)
}

func (r *RpmSuite) TestRpmRepositoryVersionPackageSearch() {
resp, err := r.client.GetRpmRepositoryByName(r.domainName, testRepoName)
require.NoError(r.T(), err)
firstVersionHref := resp.LatestVersionHref
require.NotNil(r.T(), firstVersionHref)
firstVersionHref := &r.firstVersionHref
secondVersionHref := &r.secondVersionHref

// Search first repository version
search, err := r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "bea", 100)
search, err := r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "peng", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "bear")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "cam", 100)
assert.Equal(r.T(), search[0].Name, "penguin")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "bea", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)

// Create second repository version
r.UpdateTestRepository(r.T(), testRepoURLTwo)
resp, err = r.client.GetRpmRepositoryByName(r.domainName, testRepoName)
require.NoError(r.T(), err)
secondVersionHref := resp.LatestVersionHref
require.NotNil(r.T(), secondVersionHref)

// Search second repository version, should have new package
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*secondVersionHref}, "peng", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "penguin")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*secondVersionHref}, "sto", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*secondVersionHref}, "bea", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "bear")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*secondVersionHref}, "cam", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "camel")

// Re-search the first version, should be the same
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "peng", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "penguin")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "bea", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "bear")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref}, "cam", 100)
assert.Empty(r.T(), search)

// Search both versions
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "e", 100)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 3)
assert.Equal(r.T(), "bear", search[0].Name)
assert.Equal(r.T(), "cockateel", search[1].Name)
assert.Equal(r.T(), "penguin", search[2].Name)

// Test search limit
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*secondVersionHref}, "a", 1)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 1)

// Test search empty list
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{}, "a", 1)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 0)
}

func (r *RpmSuite) TestRpmRepositoryVersionPackageGroupSearch() {
firstVersionHref := &r.firstVersionHref
secondVersionHref := &r.secondVersionHref

// Search first repository version
search, err := r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref}, "bir", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "birds")
assert.Equal(r.T(), search[0].ID, "birds")
assert.Equal(r.T(), search[0].Description, "birds")
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork"})
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref}, "mamm", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)

// Search second repository version, should have new package and removed package
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*secondVersionHref}, "bir", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "birds")
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin"})
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*secondVersionHref}, "mamm", 100)
assert.NoError(r.T(), err)
assert.ElementsMatch(r.T(), search[0].Packages, []string{"bear", "cat"})

// Re-search the first version, should be the same
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref}, "bir", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "birds")
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork"})
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref}, "mamm", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)

// Search both versions
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "a", 100)
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "s", 100)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 2)
assert.Equal(r.T(), search[0].Name, "bear")
assert.Equal(r.T(), search[1].Name, "camel")
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork"})
assert.ElementsMatch(r.T(), search[1].Packages, []string{"bear", "cat"})

// Create third repository version to remove new package
r.UpdateTestRepository(r.T(), testRepoURL)
resp, err = r.client.GetRpmRepositoryByName(r.domainName, testRepoName)
require.NoError(r.T(), err)
thirdVersionHref := resp.LatestVersionHref
require.NotNil(r.T(), thirdVersionHref)
// Test search limit
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "s", 1)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 1)

// Search third repository version, should not have new package
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*thirdVersionHref}, "bea", 100)
// Test search empty list
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{}, "a", 1)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "bear")
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*thirdVersionHref}, "cam", 100)
assert.Len(r.T(), search, 0)
}

func (r *RpmSuite) TestRpmRepositoryVersionEnvironmentSearch() {
firstVersionHref := &r.firstVersionHref
secondVersionHref := &r.secondVersionHref

// Search first repository version
search, err := r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*firstVersionHref}, "avi", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), "avians", search[0].Name)
assert.Equal(r.T(), "avians", search[0].ID)
assert.Equal(r.T(), "avians", search[0].Description)
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*firstVersionHref}, "ani", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)

// Search second repository version, should have new package and removed package
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*secondVersionHref}, "avi", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), "avians", search[0].Name)
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*secondVersionHref}, "ani", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), "animals", search[0].Name)

// Re-search the first version, should be the same
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*firstVersionHref}, "avi", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), search[0].Name, "avians")
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*firstVersionHref}, "ani", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)

// Search both versions
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "a", 100)
assert.NoError(r.T(), err)
assert.Equal(r.T(), 2, len(search))
assert.Equal(r.T(), "animals", search[0].Name)
assert.Equal(r.T(), "avians", search[1].Name)

// Test search limit
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{*secondVersionHref}, "a", 1)
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "s", 1)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 1)

// Test search empty list
search, err = r.tangy.RpmRepositoryVersionPackageSearch(context.Background(), []string{}, "a", 1)
search, err = r.tangy.RpmRepositoryVersionEnvironmentSearch(context.Background(), []string{}, "a", 1)
assert.NoError(r.T(), err)
assert.Len(r.T(), search, 0)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/tangy/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type tangyImpl struct {
//go:generate mockery --name Tangy --filename tangy_mock.go --inpackage
type Tangy interface {
RpmRepositoryVersionPackageSearch(ctx context.Context, hrefs []string, search string, limit int) ([]RpmPackageSearch, error)
RpmRepositoryVersionPackageGroupSearch(ctx context.Context, hrefs []string, search string, limit int) ([]RpmPackageGroupSearch, error)
RpmRepositoryVersionEnvironmentSearch(ctx context.Context, hrefs []string, search string, limit int) ([]RpmEnvironmentSearch, error)
Close()
}

Expand Down
Loading

0 comments on commit cf719bd

Please sign in to comment.