2023-02-02 17:15:17 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2021-04-08 20:54:32 -04:00
|
|
|
package authmethods
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestAuthenticateResultMarshaling(t *testing.T) {
|
|
|
|
|
rawJson := []byte(`{"attributes":{"key":"value"},"command":"foo"}`)
|
|
|
|
|
a := new(AuthenticateResult)
|
|
|
|
|
require.NoError(t, json.Unmarshal(rawJson, a))
|
|
|
|
|
|
|
|
|
|
exp := &AuthenticateResult{
|
|
|
|
|
Command: "foo",
|
2022-10-25 18:29:38 -05:00
|
|
|
Attributes: map[string]any{
|
2021-04-08 20:54:32 -04:00
|
|
|
"key": "value",
|
|
|
|
|
},
|
|
|
|
|
attributesRaw: json.RawMessage(`{"key":"value"}`),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require.Equal(t, exp, a)
|
|
|
|
|
|
|
|
|
|
mBytes, err := json.Marshal(exp)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
require.Equal(t, rawJson, mBytes)
|
|
|
|
|
}
|