Skip to content

Commit

Permalink
HMS 5162: add new repos for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rverdile committed Feb 7, 2025
1 parent 6507fd1 commit 52d5f33
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 41 deletions.
71 changes: 30 additions & 41 deletions internal/test/integration/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package integration

import (
"context"
"math/rand"
"testing"

"github.com/content-services/tang/internal/config"
"github.com/content-services/tang/internal/zestwrapper"
"github.com/content-services/tang/pkg/tangy"
Expand All @@ -13,6 +10,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"math/rand"
"testing"
)

type RpmSuite struct {
Expand All @@ -27,12 +26,10 @@ type RpmSuite struct {
}

const testRepoName = "zoo"
const testRepoURL = "https://rverdile.fedorapeople.org/dummy-repos/comps/repo1/"
const testRepoURLTwo = "https://rverdile.fedorapeople.org/dummy-repos/comps/repo2/"
const testRepoURL = "https://rverdile.github.io/fixtures/yum/comps-modules/v1/"
const testRepoURLTwo = "https://rverdile.github.io/fixtures/yum/comps-modules/v2/"
const testRepoNameWithErrata = "multiple-errata"
const testRepoURLWithErrata = "https://stephenw.fedorapeople.org/fakerepos/multiple_errata/"
const rpmNameWithModule = "rpm-with-modules"
const rpmUrlWithModule = "https://fixtures.pulpproject.org/rpm-with-modules-modified/"

func (r *RpmSuite) CreateTestRepository(t *testing.T, repoName string, repoUrl string) {
_, err := r.client.LookupOrCreateDomain(r.domainName)
Expand Down Expand Up @@ -160,7 +157,7 @@ func (r *RpmSuite) TestRpmRepositoryVersionPackageGroupSearch() {
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"})
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork", "duck"})
search, err = r.tangy.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref}, "mamm", 100)
assert.NoError(r.T(), err)
assert.Empty(r.T(), search)
Expand All @@ -169,7 +166,7 @@ func (r *RpmSuite) TestRpmRepositoryVersionPackageGroupSearch() {
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"})
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "duck"})
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"})
Expand All @@ -178,15 +175,15 @@ func (r *RpmSuite) TestRpmRepositoryVersionPackageGroupSearch() {
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"})
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork", "duck"})
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.RpmRepositoryVersionPackageGroupSearch(context.Background(), []string{*firstVersionHref, *secondVersionHref}, "s", 100)
assert.NoError(r.T(), err)
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork"})
assert.ElementsMatch(r.T(), search[0].Packages, []string{"cockateel", "penguin", "stork", "duck"})
assert.ElementsMatch(r.T(), search[1].Packages, []string{"bear", "cat"})

// Test search limit
Expand Down Expand Up @@ -375,22 +372,8 @@ func (r *RpmSuite) TestRpmRepositoryVersionErrataListSort() {
}

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

// expect empty
emptyList, err := r.tangy.RpmRepositoryVersionModuleStreamsList(context.Background(), []string{*firstVersionHref}, tangy.ModuleStreamListFilters{}, "name ASC")
require.NoError(r.T(), err)
assert.Empty(r.T(), emptyList)

r.CreateTestRepository(r.T(), rpmNameWithModule, rpmUrlWithModule)
resp, err = r.client.GetRpmRepositoryByName(r.domainName, rpmNameWithModule)

require.NoError(r.T(), err)
require.NotNil(r.T(), resp.LatestVersionHref)
firstVersionHref = resp.LatestVersionHref
firstVersionHref := &r.firstVersionHref
secondVersionHref := &r.secondVersionHref

// Expect populated
singleList, err := r.tangy.RpmRepositoryVersionModuleStreamsList(context.Background(), []string{*firstVersionHref}, tangy.ModuleStreamListFilters{}, "anything!")
Expand All @@ -404,13 +387,13 @@ func (r *RpmSuite) TestRpmRepositoryVersionModuleStreamsList() {
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), singleList)

// Test package name list filter
// Test module name list filter
singleList, err = r.tangy.RpmRepositoryVersionModuleStreamsList(context.Background(), []string{*firstVersionHref}, tangy.ModuleStreamListFilters{RpmNames: []string{"walrus", "kangaroo"}}, "anything DesC")
require.NoError(r.T(), err)
assert.Equal(r.T(), singleList[0].Name, "walrus")
assert.NotEmpty(r.T(), singleList)

// Test package name list filter
// Test module name list filter
singleList, err = r.tangy.RpmRepositoryVersionModuleStreamsList(context.Background(), []string{*firstVersionHref}, tangy.ModuleStreamListFilters{RpmNames: []string{"walrus", "kangaroo"}}, "name ASC")
require.NoError(r.T(), err)
assert.Equal(r.T(), singleList[0].Name, "kangaroo")
Expand All @@ -420,34 +403,40 @@ func (r *RpmSuite) TestRpmRepositoryVersionModuleStreamsList() {
singleList, err = r.tangy.RpmRepositoryVersionModuleStreamsList(context.Background(), []string{*firstVersionHref}, tangy.ModuleStreamListFilters{RpmNames: []string{"banana"}}, "")
require.NoError(r.T(), err)
assert.Empty(r.T(), singleList)

// Test no duplicated module names
singleList, err = r.tangy.RpmRepositoryVersionModuleStreamsList(context.Background(), []string{*firstVersionHref, *secondVersionHref}, tangy.ModuleStreamListFilters{RpmNames: []string{"walrus", "kangaroo"}}, "name DESC")
require.NoError(r.T(), err)
assert.Equal(r.T(), singleList[0].Name, "walrus")
assert.Len(r.T(), singleList, 1)
}

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

// no filter
singleList, total, err := r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*firstVersionHref}, tangy.RpmListFilters{Name: ""}, tangy.PageOptions{})
singleList, total, err := r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*latestVersionHref}, tangy.RpmListFilters{Name: ""}, tangy.PageOptions{})
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), singleList)
assert.Equal(r.T(), total, 4)
assert.Equal(r.T(), 9, total)

// exact match
singleList, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*firstVersionHref}, tangy.RpmListFilters{Name: "bear"}, tangy.PageOptions{})
singleList, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*latestVersionHref}, tangy.RpmListFilters{Name: "bear"}, tangy.PageOptions{})
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), singleList)
assert.Equal(r.T(), total, 1)

// partial match
singleList, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*firstVersionHref}, tangy.RpmListFilters{Name: "bea"}, tangy.PageOptions{})
singleList, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*latestVersionHref}, tangy.RpmListFilters{Name: "bea"}, tangy.PageOptions{})
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), singleList)
assert.Equal(r.T(), total, 1)

// no match
singleList, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*firstVersionHref}, tangy.RpmListFilters{Name: "wal"}, tangy.PageOptions{})
singleList, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{*latestVersionHref}, tangy.RpmListFilters{Name: "bat"}, tangy.PageOptions{})
require.NoError(r.T(), err)
assert.Empty(r.T(), singleList)
assert.Equal(r.T(), total, 0)
Expand All @@ -461,12 +450,12 @@ func (r *RpmSuite) TestRpmRepositoryVersionPackageListNoDuplicates() {
doubleList, total, err := r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{firstVersionHref, secondVersionHref}, tangy.RpmListFilters{}, tangy.PageOptions{})
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), doubleList)
assert.Equal(r.T(), total, 5)
assert.Equal(r.T(), 12, total)

singleList, total, err := r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{firstVersionHref}, tangy.RpmListFilters{}, tangy.PageOptions{})
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), singleList)
assert.Equal(r.T(), total, 3)
assert.Equal(r.T(), 7, total)
}

func (r *RpmSuite) TestRpmRepositoryVersionPackageListOffsetLimit() {
Expand All @@ -477,19 +466,19 @@ func (r *RpmSuite) TestRpmRepositoryVersionPackageListOffsetLimit() {
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), list)
assert.Equal(r.T(), 4, len(list))
assert.Equal(r.T(), 5, total)
assert.Equal(r.T(), 12, total)

list, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{firstVersionHref, secondVersionHref}, tangy.RpmListFilters{}, tangy.PageOptions{Offset: 4, Limit: 1})
require.NoError(r.T(), err)
assert.NotEmpty(r.T(), list)
assert.Equal(r.T(), 1, len(list))
assert.Equal(r.T(), 5, total)
assert.Equal(r.T(), 12, total)

list, total, err = r.tangy.RpmRepositoryVersionPackageList(context.Background(), []string{firstVersionHref, secondVersionHref}, tangy.RpmListFilters{}, tangy.PageOptions{Offset: 100, Limit: 100})
require.NoError(r.T(), err)
assert.Empty(r.T(), list)
assert.Equal(r.T(), 0, len(list))
assert.Equal(r.T(), 5, total)
assert.Equal(r.T(), 12, total)
}

func RandStringBytes(n int) string {
Expand Down
18 changes: 18 additions & 0 deletions mk/lint.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ADD_PYTHON_ENV := source .venv/bin/activate &&
GOLANGCI_LINT_VERSION := ""

.venv:
python3 -m venv .venv && $(ADD_PYTHON_ENV) pip3 install -U pip

.PHONY: install-pre-commit
install-pre-commit: install-golangci-lint .venv ## Install pre-commit linter
$(ADD_PYTHON_ENV) pip3 install pre-commit
$(ADD_PYTHON_ENV) pre-commit install --install-hooks --allow-missing-config

.PHONY: install-golangci-lint
install-golangci-lint: ## Install golangci-lint Go linter
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_OUTPUT) $(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: ## Run Go linter
$(GO_OUTPUT)/golangci-lint run --fix

0 comments on commit 52d5f33

Please sign in to comment.