mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 13:55:55 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package proxycfg
|
|
|
|
import (
|
|
"context"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/google/go-cmp/cmp/cmpopts"
|
|
fuzz "github.com/google/gofuzz"
|
|
"github.com/hashicorp/consul/proto/private/pbpeering"
|
|
)
|
|
|
|
func TestConfigSnapshot_Clone(t *testing.T) {
|
|
// ConfigSnapshot is a complex struct that (directly or indirectly) has a copy
|
|
// of most of the structs in the agent/structs package. It'd be easy to break
|
|
// the Clone method accidentally by changing one of those distant structs, so
|
|
// we test it by using a fuzzer to traverse the graph and fill every field and
|
|
// then compare the original to the copy.
|
|
f := fuzz.New()
|
|
f.NilChance(0)
|
|
f.NumElements(1, 3)
|
|
f.SkipFieldsWithPattern(regexp.MustCompile("^ServerSNIFn$"))
|
|
|
|
f.Funcs(
|
|
// Populate map[string]interface{} since gofuzz panics on these. We force them
|
|
// to be any rather than concrete types otherwise they won't compare equal when
|
|
// coming back out the other side.
|
|
func(m map[string]any, c fuzz.Continue) {
|
|
m[c.RandString()] = any(float64(c.RandUint64()))
|
|
m[c.RandString()] = any(c.RandString())
|
|
m[c.RandString()] = any([]any{c.RandString(), c.RandString()})
|
|
m[c.RandString()] = any(map[string]any{c.RandString(): c.RandString()})
|
|
},
|
|
func(*context.CancelFunc, fuzz.Continue) {},
|
|
)
|
|
|
|
snapshot := new(ConfigSnapshot)
|
|
f.Fuzz(snapshot)
|
|
|
|
clone := snapshot.Clone()
|
|
|
|
diff := cmp.Diff(snapshot, clone,
|
|
cmpopts.IgnoreUnexported(indexedTarget{}),
|
|
cmpopts.IgnoreUnexported(pbpeering.PeeringTrustBundle{}),
|
|
cmpopts.IgnoreTypes(context.CancelFunc(nil)),
|
|
)
|
|
if diff != "" {
|
|
t.Logf("Copied snaspshot is different to the original. You may need to re-run `make deep-copy`.\nDiff:\n%s", diff)
|
|
t.FailNow()
|
|
}
|
|
}
|