2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-13 10:23:19 -04:00
|
|
|
package resources
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-08-29 08:30:20 -04:00
|
|
|
"github.com/edgelesssys/constellation/internal/kubernetes"
|
2022-06-13 10:23:19 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-06-30 09:24:36 -04:00
|
|
|
"go.uber.org/goleak"
|
2022-06-13 10:23:19 -04:00
|
|
|
)
|
|
|
|
|
2022-06-30 09:24:36 -04:00
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
goleak.VerifyTestMain(m)
|
|
|
|
}
|
|
|
|
|
2022-06-13 10:23:19 -04:00
|
|
|
func TestAccessManagerMarshalUnmarshal(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
// Without data
|
|
|
|
accessManagerDeplNil := NewAccessManagerDeployment(nil)
|
|
|
|
data, err := accessManagerDeplNil.Marshal()
|
|
|
|
require.NoError(err)
|
|
|
|
|
|
|
|
var recreated accessManagerDeployment
|
2022-08-29 08:30:20 -04:00
|
|
|
require.NoError(kubernetes.UnmarshalK8SResources(data, &recreated))
|
2022-06-13 10:23:19 -04:00
|
|
|
assert.Equal(accessManagerDeplNil, &recreated)
|
|
|
|
|
|
|
|
// With data
|
|
|
|
sshUsers := make(map[string]string)
|
|
|
|
sshUsers["test-user"] = "ssh-rsa abcdefg"
|
|
|
|
accessManagerDeplNil = NewAccessManagerDeployment(sshUsers)
|
|
|
|
data, err = accessManagerDeplNil.Marshal()
|
|
|
|
require.NoError(err)
|
|
|
|
|
2022-08-29 08:30:20 -04:00
|
|
|
require.NoError(kubernetes.UnmarshalK8SResources(data, &recreated))
|
2022-06-13 10:23:19 -04:00
|
|
|
assert.Equal(accessManagerDeplNil, &recreated)
|
|
|
|
}
|