mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-29 18:21:10 +00:00
feat(vm2): add initial support for `cdrom` This is a breaking change comparing to v1 - switching the cdrom schema from a nested block to a nested attribute map. Improvements comparing to v1: - support for `ide`, `sata`, `scsi` interfaces - support for multiple cdroms Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
92 lines
1.9 KiB
Go
92 lines
1.9 KiB
Go
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetDiff(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
type args[T any] struct {
|
|
plan []T
|
|
state []T
|
|
}
|
|
|
|
type testCase[T any] struct {
|
|
name string
|
|
args args[T]
|
|
wantToCreate []T
|
|
wantToUpdate []T
|
|
wantToDelete []T
|
|
}
|
|
|
|
type rec struct {
|
|
n string
|
|
v string
|
|
}
|
|
|
|
tests := []testCase[rec]{
|
|
{
|
|
name: "empty",
|
|
args: args[rec]{
|
|
plan: []rec{},
|
|
state: []rec{},
|
|
},
|
|
wantToCreate: nil,
|
|
wantToUpdate: nil,
|
|
wantToDelete: nil,
|
|
},
|
|
{
|
|
name: "create",
|
|
args: args[rec]{
|
|
plan: []rec{{"a", "1"}, {"b", "2"}, {"c", "3"}},
|
|
state: []rec{},
|
|
},
|
|
wantToCreate: []rec{{"a", "1"}, {"b", "2"}, {"c", "3"}},
|
|
wantToUpdate: nil,
|
|
wantToDelete: nil,
|
|
},
|
|
{
|
|
name: "create and delete",
|
|
args: args[rec]{
|
|
plan: []rec{{"a", "1"}, {"b", "2"}, {"c", "3"}},
|
|
state: []rec{{"b", "2"}, {"c", "3"}, {"d", "4"}},
|
|
},
|
|
wantToCreate: []rec{{"a", "1"}},
|
|
wantToUpdate: nil,
|
|
wantToDelete: []rec{{"d", "4"}},
|
|
},
|
|
{
|
|
name: "update",
|
|
args: args[rec]{
|
|
plan: []rec{{"a", "1"}, {"b", "2"}, {"c", "3"}},
|
|
state: []rec{{"a", "1"}, {"b", "2"}, {"c", "4"}},
|
|
},
|
|
wantToCreate: nil,
|
|
wantToUpdate: []rec{{"c", "3"}},
|
|
wantToDelete: nil,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
gotToCreate, gotToUpdate, gotToDelete := SetDiff(
|
|
tt.args.plan, tt.args.state, func(t rec) string { return t.n },
|
|
)
|
|
assert.Equalf(t, tt.wantToCreate, gotToCreate, "toCreate is different")
|
|
assert.Equalf(t, tt.wantToUpdate, gotToUpdate, "toUpdate is different")
|
|
assert.Equalf(t, tt.wantToDelete, gotToDelete, "toDelete is different")
|
|
})
|
|
}
|
|
}
|