-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Require components to opt out of auto release calculation #100
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
Changes from 2 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 |
|---|---|---|
|
|
@@ -463,6 +463,10 @@ func (r *Resolver) createComponentFromConfig(componentConfig *projectconfig.Comp | |
| componentConfig.Name, err) | ||
| } | ||
|
|
||
| if componentConfig.ReleaseCalculation == "" { | ||
| componentConfig.ReleaseCalculation = projectconfig.ReleaseCalculationAuto | ||
| } | ||
|
||
|
|
||
| return &resolvedComponent{ | ||
| env: r.env, | ||
| config: *componentConfig, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package sources | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/microsoft/azure-linux-dev-tools/internal/app/azldev/core/components/components_testutils" | ||
| "github.com/microsoft/azure-linux-dev-tools/internal/projectconfig" | ||
| "github.com/microsoft/azure-linux-dev-tools/internal/utils/fileperms" | ||
| "github.com/microsoft/azure-linux-dev-tools/internal/utils/fileutils" | ||
| "github.com/spf13/afero" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "go.uber.org/mock/gomock" | ||
| ) | ||
|
|
||
| const testSourcesDir = "/sources" | ||
|
|
||
| func newTestPreparer(memFS afero.Fs) *sourcePreparerImpl { | ||
| return &sourcePreparerImpl{ | ||
| fs: memFS, | ||
| } | ||
| } | ||
|
|
||
| func writeTestSpec(t *testing.T, memFS afero.Fs, name, release string) { | ||
| t.Helper() | ||
|
|
||
| specDir := filepath.Join(testSourcesDir, name) | ||
| require.NoError(t, fileutils.MkdirAll(memFS, specDir)) | ||
|
|
||
| specPath := filepath.Join(specDir, name+".spec") | ||
| content := []byte("Name: " + name + "\nVersion: 1.0.0\nRelease: " + release + "\nSummary: Test\nLicense: MIT\n") | ||
|
|
||
| require.NoError(t, fileutils.WriteFile(memFS, specPath, content, fileperms.PublicFile)) | ||
| } | ||
|
|
||
| func mockComponent( | ||
| ctrl *gomock.Controller, name string, config *projectconfig.ComponentConfig, | ||
| ) *components_testutils.MockComponent { | ||
| comp := components_testutils.NewMockComponent(ctrl) | ||
| comp.EXPECT().GetName().AnyTimes().Return(name) | ||
| comp.EXPECT().GetConfig().AnyTimes().Return(config) | ||
|
|
||
| return comp | ||
| } | ||
|
|
||
| func TestTryBumpStaticRelease_ManualSkips(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| memFS := afero.NewMemMapFs() | ||
| preparer := newTestPreparer(memFS) | ||
|
|
||
| comp := mockComponent(ctrl, "kernel", &projectconfig.ComponentConfig{ | ||
| ReleaseCalculation: projectconfig.ReleaseCalculationManual, | ||
| }) | ||
|
|
||
| // No spec file needed — should skip before reading anything. | ||
| err := preparer.tryBumpStaticRelease(comp, testSourcesDir, 3) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestTryBumpStaticRelease_AutoreleaseSkips(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| memFS := afero.NewMemMapFs() | ||
| preparer := newTestPreparer(memFS) | ||
|
|
||
| writeTestSpec(t, memFS, "test-pkg", "%autorelease") | ||
|
|
||
| comp := mockComponent(ctrl, "test-pkg", &projectconfig.ComponentConfig{ | ||
| ReleaseCalculation: projectconfig.ReleaseCalculationAuto, | ||
| }) | ||
|
|
||
| err := preparer.tryBumpStaticRelease(comp, filepath.Join(testSourcesDir, "test-pkg"), 3) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestTryBumpStaticRelease_StaticBumps(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| memFS := afero.NewMemMapFs() | ||
| preparer := newTestPreparer(memFS) | ||
|
|
||
| writeTestSpec(t, memFS, "test-pkg", "1%{?dist}") | ||
|
|
||
| comp := mockComponent(ctrl, "test-pkg", &projectconfig.ComponentConfig{ | ||
| ReleaseCalculation: projectconfig.ReleaseCalculationAuto, | ||
| }) | ||
|
|
||
| err := preparer.tryBumpStaticRelease(comp, filepath.Join(testSourcesDir, "test-pkg"), 3) | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify the spec was updated. | ||
| specPath := filepath.Join(testSourcesDir, "test-pkg", "test-pkg.spec") | ||
| content, err := fileutils.ReadFile(memFS, specPath) | ||
| require.NoError(t, err) | ||
| assert.Contains(t, string(content), "Release: 4%{?dist}") | ||
| } | ||
|
|
||
| func TestTryBumpStaticRelease_NonStandardErrorsWithoutManual(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| memFS := afero.NewMemMapFs() | ||
| preparer := newTestPreparer(memFS) | ||
|
|
||
| writeTestSpec(t, memFS, "kernel", "%{pkg_release}") | ||
|
|
||
| comp := mockComponent(ctrl, "kernel", &projectconfig.ComponentConfig{ | ||
| ReleaseCalculation: projectconfig.ReleaseCalculationAuto, | ||
| }) | ||
|
|
||
| err := preparer.tryBumpStaticRelease(comp, filepath.Join(testSourcesDir, "kernel"), 3) | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), "cannot be auto-bumped") | ||
| assert.Contains(t, err.Error(), "release-calculation") | ||
| } | ||
|
|
||
| func TestTryBumpStaticRelease_NonStandardSucceedsWithManual(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| memFS := afero.NewMemMapFs() | ||
| preparer := newTestPreparer(memFS) | ||
|
|
||
| writeTestSpec(t, memFS, "kernel", "%{pkg_release}") | ||
|
|
||
| comp := mockComponent(ctrl, "kernel", &projectconfig.ComponentConfig{ | ||
| ReleaseCalculation: projectconfig.ReleaseCalculationManual, | ||
| }) | ||
|
|
||
| err := preparer.tryBumpStaticRelease(comp, filepath.Join(testSourcesDir, "kernel"), 3) | ||
| require.NoError(t, err) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.