// Currently the storage-locations parameter is tested in utils_test/TestSnapshotStorageLocations.
// Here we just test other parameters.
Currently the storage-locations parameter is tested in utils_test/TestSnapshotStorageLocations.
Here we just test other parameters.
// Currently the storage - locations parameter is tested in utils_test / TestSnapshotStorageLocations . // Here we just test other parameters .
func TestSnapshotParameters(t *testing.T) {
	tests := []struct {
		desc                    string
		parameters              map[string]string
		expectedSnapshotParames SnapshotParameters
		expectError             bool
	}{
		{
			desc: "valid parameter",
			parameters: map[string]string{
				ParameterKeyStorageLocations:          "ASIA ",
				ParameterKeySnapshotType:              "images",
				ParameterKeyImageFamily:               "test-family",
				ParameterKeyVolumeSnapshotName:        "snapshot-name",
				ParameterKeyVolumeSnapshotContentName: "snapshot-content-name",
				ParameterKeyVolumeSnapshotNamespace:   "snapshot-namespace",
			},
			expectedSnapshotParames: SnapshotParameters{
				StorageLocations: []string{"asia"},
				SnapshotType:     DiskImageType,
				ImageFamily:      "test-family",
				Tags: map[string]string{
					tagKeyCreatedForSnapshotName:        "snapshot-name",
					tagKeyCreatedForSnapshotContentName: "snapshot-content-name",
					tagKeyCreatedForSnapshotNamespace:   "snapshot-namespace",
					tagKeyCreatedBy:                     "test-driver",
				},
			},
			expectError: false,
		},
		{
			desc:       "nil parameter",
			parameters: nil,
			expectedSnapshotParames: SnapshotParameters{
				StorageLocations: []string{},
				SnapshotType:     DiskSnapshotType,
				Tags:             make(map[string]string),
			},
			expectError: false,
		},
		{
			desc:        "invalid snapshot type",
			parameters:  map[string]string{ParameterKeySnapshotType: "invalid-type"},
			expectError: true,
		},
	}
	for _, tc := range tests {
		t.Run(tc.desc, func(t *testing.T) {
			p, err := ExtractAndDefaultSnapshotParameters(tc.parameters, "test-driver")
			if err != nil && !tc.expectError {
				t.Errorf("Got error %v; expect no error", err)
			}
			if err == nil && tc.expectError {
				t.Error("Got no error; expect an error")
			}
			if err == nil && !reflect.DeepEqual(p, tc.expectedSnapshotParames) {
				t.Errorf("Got ExtractAndDefaultSnapshotParameters(%+v) = %+v; expect %+v", tc.parameters, p, tc.expectedSnapshotParames)
			}
		})
	}
}
func TestSnapshotParameters ( t * testing . T ) { tests := [ ] struct { desc string parameters map [ string ] string expectedSnapshotParames SnapshotParameters expectError bool } { { desc : " " , parameters : map [ string ] string { ParameterKeyStorageLocations : " " , ParameterKeySnapshotType : " " , ParameterKeyImageFamily : " " , ParameterKeyVolumeSnapshotName : " " , ParameterKeyVolumeSnapshotContentName : " " , ParameterKeyVolumeSnapshotNamespace : " " , } , expectedSnapshotParames : SnapshotParameters { StorageLocations : [ ] string { " " } , SnapshotType : DiskImageType , ImageFamily : " " , Tags : map [ string ] string { tagKeyCreatedForSnapshotName : " " , tagKeyCreatedForSnapshotContentName : " " , tagKeyCreatedForSnapshotNamespace : " " , tagKeyCreatedBy : " " , } , } , expectError : false , } , { desc : " " , parameters : nil , expectedSnapshotParames : SnapshotParameters { StorageLocations : [ ] string { } , SnapshotType : DiskSnapshotType , Tags : make ( map [ string ] string ) , } , expectError : false , } , { desc : " " , parameters : map [ string ] string { ParameterKeySnapshotType : " " } , expectError : true , } , } for _ , tc := range tests { t . Run ( tc . desc , func ( t * testing . T ) { p , err := ExtractAndDefaultSnapshotParameters ( tc . parameters , " " ) if err != nil && ! tc . expectError { t . Errorf ( " " , err ) } if err == nil && tc . expectError { t . Error ( " " ) } if err == nil && ! reflect . DeepEqual ( p , tc . expectedSnapshotParames ) { t . Errorf ( " " , tc . parameters , p , tc . expectedSnapshotParames ) } } ) } }
Currently the storage-locations parameter is tested in utils_test/TestSnapshotStorageLocations.
Currently the storage - locations parameter is tested in utils_test / TestSnapshotStorageLocations .