Skip to content

Commit d9a0b5c

Browse files
authored
feat: add --no-check to advanced mock build-rpms (#444)
1 parent 9e97fd1 commit d9a0b5c

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

internal/app/azldev/cmds/advanced/mock.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type BuildRPMOptions struct {
4646
SRPMPath string
4747
// Path to the output directory for final RPM files.
4848
OutputDirPath string
49+
// Whether to skip the %check section of the RPM spec.
50+
NoCheck bool
4951
}
5052

5153
// Constructs a [cobra.Command] for the "mock build-rpms" subcommand.
@@ -64,6 +66,7 @@ func NewBuildRPMCmd() *cobra.Command {
6466
cmd.Flags().StringVarP(&options.MockConfigPath, "config", "c", "", "Path to the mock .cfg file")
6567
cmd.Flags().StringVar(&options.SRPMPath, "srpm", "", "Path to the SRPM to build")
6668
cmd.Flags().StringVarP(&options.OutputDirPath, "output-dir", "o", "", "Path to output directory")
69+
cmd.Flags().BoolVar(&options.NoCheck, "no-check", false, "Skip package %check tests")
6770

6871
_ = cmd.MarkFlagRequired("srpm")
6972
_ = cmd.MarkFlagRequired("output-dir")
@@ -114,7 +117,9 @@ func BuildRPMS(env *azldev.Env, options *BuildRPMOptions) (results interface{},
114117
return results, err
115118
}
116119

117-
buildOptions := mock.RPMBuildOptions{}
120+
buildOptions := mock.RPMBuildOptions{
121+
NoCheck: options.NoCheck,
122+
}
118123

119124
evt := env.StartEvent("Building RPM with mock",
120125
"srpmPath", options.SRPMPath, "outputDirPath", options.OutputDirPath)

internal/app/azldev/cmds/advanced/mock_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,48 @@ func TestBuildRPMS(t *testing.T) {
6262
require.Equal(t, true, result)
6363
})
6464

65+
t.Run("NoCheck", func(t *testing.T) {
66+
// Construct a new env with no configuration.
67+
testEnv := testutils.NewTestEnv(t)
68+
69+
// Pretend that "mock" exists.
70+
testEnv.CmdFactory.RegisterCommandInSearchPath("mock")
71+
72+
// Keep track of what commands get launched.
73+
cmds := [][]string{}
74+
testEnv.CmdFactory.RunHandler = func(cmd *exec.Cmd) error {
75+
cmds = append(cmds, cmd.Args)
76+
77+
return nil
78+
}
79+
80+
rpmOptions := &advanced.BuildRPMOptions{
81+
MockCmdOptions: advanced.MockCmdOptions{
82+
MockConfigPath: testMockConfigPath,
83+
},
84+
SRPMPath: testSRPMPath,
85+
OutputDirPath: testOutputDirPath,
86+
NoCheck: true,
87+
}
88+
89+
result, err := advanced.BuildRPMS(testEnv.Env, rpmOptions)
90+
require.NoError(t, err)
91+
require.Equal(t, true, result)
92+
93+
// Verify that '--nocheck' was passed to mock.
94+
found := false
95+
96+
for _, cmd := range cmds {
97+
if slices.Contains(cmd, "mock") && slices.Contains(cmd, "--nocheck") {
98+
found = true
99+
100+
break
101+
}
102+
}
103+
104+
require.True(t, found, "Expected '--nocheck' flag to be passed to mock")
105+
})
106+
65107
t.Run("ValidProjectConfig", func(t *testing.T) {
66108
testEnv := testutils.NewTestEnv(t)
67109

0 commit comments

Comments
 (0)