-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package dynamic | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type FakeConfig struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
// DeepCopyInto is a deepcopy function, copying the receiver, writing into out. in must be non-nil. | ||
func (in *FakeConfig) DeepCopyInto(out *FakeConfig) { | ||
*out = *in | ||
} | ||
|
||
// DeepCopy is a deepcopy function, copying the receiver, creating a new AddPrefix. | ||
func (in *FakeConfig) DeepCopy() *FakeConfig { | ||
if in == nil { | ||
return nil | ||
} | ||
out := new(FakeConfig) | ||
in.DeepCopyInto(out) | ||
return out | ||
} | ||
|
||
type Foo struct { | ||
Name string | ||
} | ||
|
||
func TestPluginConf_DeepCopy_mapOfStruct(t *testing.T) { | ||
f := &FakeConfig{Name: "bir"} | ||
p := PluginConf{ | ||
"fii": f, | ||
} | ||
|
||
clone := p.DeepCopy() | ||
assert.Equal(t, &p, clone) | ||
|
||
f.Name = "bur" | ||
|
||
assert.NotEqual(t, &p, clone) | ||
} | ||
|
||
func TestPluginConf_DeepCopy_map(t *testing.T) { | ||
m := map[string]interface{}{ | ||
"name": "bar", | ||
} | ||
p := PluginConf{ | ||
"config": map[string]interface{}{ | ||
"foo": m, | ||
}, | ||
} | ||
|
||
clone := p.DeepCopy() | ||
assert.Equal(t, &p, clone) | ||
|
||
p["one"] = "a" | ||
m["two"] = "b" | ||
|
||
assert.NotEqual(t, &p, clone) | ||
} | ||
|
||
func TestPluginConf_DeepCopy_panic(t *testing.T) { | ||
p := &PluginConf{ | ||
"config": map[string]interface{}{ | ||
"foo": &Foo{Name: "gigi"}, | ||
}, | ||
} | ||
|
||
assert.Panics(t, func() { | ||
p.DeepCopy() | ||
}) | ||
} |