2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-05-16 11:32:00 -04:00
|
|
|
package ssh
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestToAndFromProtoSlice(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
DemoSSHUser1 := UserKey{
|
|
|
|
Username: "test-user-2",
|
|
|
|
PublicKey: "ssh-rsa abcdefg",
|
|
|
|
}
|
|
|
|
|
|
|
|
DemoSSHUser2 := UserKey{
|
|
|
|
Username: "test-user-2",
|
|
|
|
PublicKey: "ssh-rsa hijklmnop",
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input usually consists of pointers (from config parsing)
|
|
|
|
DemoSSHUsersPointers := make([]*UserKey, 0)
|
|
|
|
DemoSSHUsersPointers = append(DemoSSHUsersPointers, &DemoSSHUser1)
|
|
|
|
DemoSSHUsersPointers = append(DemoSSHUsersPointers, &DemoSSHUser2)
|
|
|
|
|
|
|
|
// Expected output usually does not consist of pointers
|
|
|
|
DemoSSHUsersNoPointers := make([]UserKey, 0)
|
|
|
|
DemoSSHUsersNoPointers = append(DemoSSHUsersNoPointers, DemoSSHUser1)
|
|
|
|
DemoSSHUsersNoPointers = append(DemoSSHUsersNoPointers, DemoSSHUser2)
|
|
|
|
|
|
|
|
ToProtoArray := ToProtoSlice(DemoSSHUsersPointers)
|
|
|
|
FromProtoArray := FromProtoSlice(ToProtoArray)
|
|
|
|
|
|
|
|
assert.Equal(DemoSSHUsersNoPointers, FromProtoArray)
|
|
|
|
}
|