Merge pull request #5980 from thaJeztah/container_use_subtests

cli/command/container: TestNewCreateCommandWithContentTrustErrors use subtests
This commit is contained in:
Sebastiaan van Stijn 2025-04-01 16:24:05 +02:00 committed by GitHub
commit 33494921b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -248,23 +248,25 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
fakeCLI := test.NewFakeCli(&fakeClient{ t.Run(tc.name, func(t *testing.T) {
createContainerFunc: func(config *container.Config, fakeCLI := test.NewFakeCli(&fakeClient{
hostConfig *container.HostConfig, createContainerFunc: func(config *container.Config,
networkingConfig *network.NetworkingConfig, hostConfig *container.HostConfig,
platform *specs.Platform, networkingConfig *network.NetworkingConfig,
containerName string, platform *specs.Platform,
) (container.CreateResponse, error) { containerName string,
return container.CreateResponse{}, errors.New("shouldn't try to pull image") ) (container.CreateResponse, error) {
}, return container.CreateResponse{}, errors.New("shouldn't try to pull image")
}, test.EnableContentTrust) },
fakeCLI.SetNotaryClient(tc.notaryFunc) }, test.EnableContentTrust)
cmd := NewCreateCommand(fakeCLI) fakeCLI.SetNotaryClient(tc.notaryFunc)
cmd.SetOut(io.Discard) cmd := NewCreateCommand(fakeCLI)
cmd.SetErr(io.Discard) cmd.SetOut(io.Discard)
cmd.SetArgs(tc.args) cmd.SetErr(io.Discard)
err := cmd.Execute() cmd.SetArgs(tc.args)
assert.ErrorContains(t, err, tc.expectedError) err := cmd.Execute()
assert.ErrorContains(t, err, tc.expectedError)
})
} }
} }