Files
podman/pkg/domain/utils/scp_test.go
Zachary Hanham feb46513f0 scp: add option types
Prior to this commit, many scp functions existed without option structs, which would make extending functionality (adding new options) impossible without breaking changes, or without adding redundant wrapper functions.

This commit adds in new option types for various scp related functions, and changes those functions' signatures to use the new options.

This commit also modifies the `ImageEngine.Scp()` function's interface to use the new opts.

The commit also renames the existing `ImageScpOptions` entity type to `ScpTransferImageOptions`. This is because the previous `ImageScpOptions` was inaccurate, as it is not the actual options for `ImageEngine.Scp()`. `ImageEngine.Scp()` should instead receive `ImageScpOptions`.

This commit should not change any behavior, however it will break the existing functions' signatures.

Signed-off-by: Zachary Hanham <z.hanham00@gmail.com>
2024-10-14 21:46:55 -04:00

75 lines
1.3 KiB
Go

package utils
import (
"fmt"
"testing"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/stretchr/testify/assert"
)
func TestValidateSCPArgs(t *testing.T) {
type args struct {
locations []*entities.ScpTransferImageOptions
}
tests := []struct {
name string
args args
wantErr assert.ErrorAssertionFunc
}{
{
name: "test args length more than 2",
args: args{
locations: []*entities.ScpTransferImageOptions{
{
Image: "source image one",
},
{
Image: "source image two",
},
{
Image: "target image one",
},
{
Image: "target image two",
},
},
},
wantErr: assert.Error,
},
{
name: "test source image is empty",
args: args{
locations: []*entities.ScpTransferImageOptions{
{
Image: "",
},
{
Image: "target image",
},
},
},
wantErr: assert.NoError,
},
{
name: "test target image is empty",
args: args{
locations: []*entities.ScpTransferImageOptions{
{
Image: "source image",
},
{
Image: "target image",
},
},
},
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.wantErr(t, ValidateSCPArgs(tt.args.locations), fmt.Sprintf("ValidateSCPArgs(%v)", tt.args.locations))
})
}
}