-
Notifications
You must be signed in to change notification settings - Fork 13
fix: support upstream specs in component query #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,3 +80,86 @@ func TestQueryComponents_OneComponent(t *testing.T) { | |
| result := results[0] | ||
| assert.Equal(t, testComponentName, result.Name) | ||
| } | ||
|
|
||
| func TestQueryComponents_UpstreamComponent(t *testing.T) { | ||
| const testComponentName = "test-component" | ||
| const testUpstreamName = "test-component-upstream" | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| component projectconfig.ComponentConfig | ||
| specFileName string | ||
| specNameField string | ||
| }{ | ||
| { | ||
| name: "default spec source type uses normalized component name", | ||
| component: projectconfig.ComponentConfig{ | ||
| Name: testComponentName, | ||
| }, | ||
| specFileName: testComponentName, | ||
| specNameField: testComponentName, | ||
| }, | ||
| { | ||
| name: "explicit upstream spec source type uses upstream name", | ||
| component: projectconfig.ComponentConfig{ | ||
| Name: testComponentName, | ||
| Spec: projectconfig.SpecConfig{ | ||
| SourceType: projectconfig.SpecSourceTypeUpstream, | ||
| UpstreamName: testUpstreamName, | ||
| }, | ||
| }, | ||
|
Comment on lines
+104
to
+110
|
||
| specFileName: testUpstreamName, | ||
| specNameField: testUpstreamName, | ||
| }, | ||
| } | ||
|
|
||
| for _, testCase := range testCases { | ||
| t.Run(testCase.name, func(t *testing.T) { | ||
| testEnv := testutils.NewTestEnv(t) | ||
| testEnv.Config.Components[testComponentName] = testCase.component | ||
|
|
||
| testEnv.CmdFactory.RegisterCommandInSearchPath(mock.MockBinary) | ||
|
|
||
| testEnv.CmdFactory.RunHandler = func(cmd *exec.Cmd) error { | ||
| if len(cmd.Args) >= 2 && cmd.Args[0] == "git" && cmd.Args[1] == "clone" { | ||
| cloneDir := cmd.Args[len(cmd.Args)-1] | ||
| specPath := cloneDir + "/" + testCase.specFileName + ".spec" | ||
|
|
||
| return fileutils.WriteFile( | ||
| testEnv.FS(), | ||
| specPath, | ||
| []byte("Name: "+testCase.specNameField+"\nVersion: 1.0.0\n"), | ||
| fileperms.PublicFile, | ||
| ) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| testEnv.CmdFactory.RunAndGetOutputHandler = func(cmd *exec.Cmd) (string, error) { | ||
| if len(cmd.Args) >= 5 && | ||
| cmd.Args[0] == "git" && | ||
| cmd.Args[1] == "-C" && | ||
| cmd.Args[3] == "rev-parse" && | ||
| cmd.Args[4] == "HEAD" { | ||
| return "head123abc\n", nil | ||
| } | ||
|
|
||
| return "name=test-component\nepoch=0\nversion=1.0.0\nrelease=1.azl3\n", nil | ||
| } | ||
|
Comment on lines
+139
to
+149
|
||
|
|
||
| options := component.QueryComponentsOptions{ | ||
| ComponentFilter: components.ComponentFilter{ | ||
| ComponentNamePatterns: []string{testComponentName}, | ||
| }, | ||
| } | ||
|
|
||
| results, err := component.QueryComponents(testEnv.Env, &options) | ||
| require.NoError(t, err) | ||
| require.Len(t, results, 1) | ||
|
|
||
| result := results[0] | ||
| assert.Equal(t, testComponentName, result.Name) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseComponentSpecprepares upstream sources without enabling dist-git / synthetic history (sources.WithGitRepo). In other paths (e.g., component render)WithGitRepois used so rpmautospec can expand%autorelease/%autochangelogcorrectly and to keep release numbering consistent with overlay commit count. As written,component querymay produce incorrect release/changelog values (or fail) for specs that rely on rpmautospec because the upstream.gitdir is removed and no synthetic commits are created. Consider aligning this with render by addingsources.WithGitRepo(env.Config().Project.DefaultAuthorEmail)(or otherwise preserving.git+ synthetic history) for this query-only prep path, or explicitly disabling rpmautospec-dependent expansion and documenting the limitation.