本文整理匯總了Golang中k8s/io/kubernetes/pkg/api/resource.Quantity.DeepCopy方法的典型用法代碼示例。如果您正苦於以下問題:Golang Quantity.DeepCopy方法的具體用法?Golang Quantity.DeepCopy怎麽用?Golang Quantity.DeepCopy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/api/resource.Quantity
的用法示例。
在下文中一共展示了Quantity.DeepCopy方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDeepCopy
func TestDeepCopy(t *testing.T) {
make := func() *api.ClusterResourceQuota {
q := resource.Quantity{}
q.Set(100)
crq := &api.ClusterResourceQuota{}
crq.Status.Namespaces.Insert("ns1", kapi.ResourceQuotaStatus{Hard: kapi.ResourceList{"a": q.DeepCopy()}, Used: kapi.ResourceList{"a": q.DeepCopy()}})
crq.Status.Namespaces.Insert("ns2", kapi.ResourceQuotaStatus{Hard: kapi.ResourceList{"b": q.DeepCopy()}, Used: kapi.ResourceList{"b": q.DeepCopy()}})
return crq
}
check := make()
original := make()
if !reflect.DeepEqual(check, original) {
t.Error("before mutation of copy, check and original should be identical but are not, likely failure in deepequal")
}
if !kapi.Semantic.DeepEqual(check, original) {
t.Error("before mutation of copy, check and original should be identical but are not, likely failure in deepequal")
}
copiedObj, err := kapi.Scheme.Copy(original)
if err != nil {
t.Fatal(err)
}
copied := copiedObj.(*api.ClusterResourceQuota)
if !reflect.DeepEqual(copied, original) {
t.Error("before mutation of copy, copied and original should be identical but are not, likely failure in deepequal")
}
if !kapi.Semantic.DeepEqual(copied, original) {
t.Error("before mutation of copy, copied and original should be identical but are not, likely failure in deepequal")
}
// Mutate the copy
for e := copied.Status.Namespaces.OrderedKeys().Front(); e != nil; e = e.Next() {
k := e.Value.(string)
ns, _ := copied.Status.Namespaces.Get(k)
for k2, v2 := range ns.Hard {
v2.Set(v2.Value() + 2)
ns.Hard[k2] = v2
}
for k2, v2 := range ns.Used {
v2.Set(v2.Value() + 1)
ns.Used[k2] = v2
}
copied.Status.Namespaces.Insert(k, ns)
}
if !reflect.DeepEqual(check, original) {
t.Error("after mutation of copy, check and original should be identical but are not, likely failure in deep copy (ensure custom DeepCopy is being used)")
}
if !kapi.Semantic.DeepEqual(check, original) {
t.Error("after mutation of copy, check and original should be identical but are not, likely failure in deep copy (ensure custom DeepCopy is being used)")
}
if reflect.DeepEqual(original, copied) {
t.Error("after mutation of copy, original and copied should be different but are not, likely failure in deep copy (ensure custom DeepCopy is being used)")
}
if kapi.Semantic.DeepEqual(original, copied) {
t.Error("after mutation of copy, original and copied should be different but are not, likely failure in deep copy (ensure custom DeepCopy is being used)")
}
}