|
95 | 95 | }, |
96 | 96 | }, |
97 | 97 | } |
98 | | - validClaim = testClaim(goodName, goodNS, validClaimSpec) |
| 98 | + validClaim = testClaim(goodName, goodNS, validClaimSpec) |
| 99 | + conditionValidationErrMessage = "name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')" |
99 | 100 | ) |
100 | 101 |
|
101 | 102 | func TestValidateClaim(t *testing.T) { |
@@ -1701,6 +1702,145 @@ func TestValidateClaimStatusUpdate(t *testing.T) { |
1701 | 1702 | }, |
1702 | 1703 | prioritizedListFeatureGate: false, |
1703 | 1704 | }, |
| 1705 | + "good-binding-conditions": { |
| 1706 | + oldClaim: validClaim, |
| 1707 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1708 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1709 | + Devices: resource.DeviceAllocationResult{ |
| 1710 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1711 | + Request: goodName, |
| 1712 | + Driver: goodName, |
| 1713 | + Pool: goodName, |
| 1714 | + Device: goodName, |
| 1715 | + AdminAccess: ptr.To(false), |
| 1716 | + BindingConditions: []string{"example.com/condition1", "condition2", "condition3", "condition4"}, |
| 1717 | + BindingFailureConditions: []string{"example.com/condition5", "condition6", "condition7", "condition8"}, |
| 1718 | + }}, |
| 1719 | + }, |
| 1720 | + } |
| 1721 | + return claim |
| 1722 | + }, |
| 1723 | + }, |
| 1724 | + "too-many-binding-conditions": { |
| 1725 | + wantFailures: field.ErrorList{field.TooMany(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("bindingConditions"), 5, 4)}, |
| 1726 | + oldClaim: validClaim, |
| 1727 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1728 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1729 | + Devices: resource.DeviceAllocationResult{ |
| 1730 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1731 | + Request: goodName, |
| 1732 | + Driver: goodName, |
| 1733 | + Pool: goodName, |
| 1734 | + Device: goodName, |
| 1735 | + AdminAccess: ptr.To(false), |
| 1736 | + BindingConditions: []string{"condition1", "condition2", "condition3", "condition4", "condition5"}, |
| 1737 | + BindingFailureConditions: []string{"condition6", "condition7"}, |
| 1738 | + }}, |
| 1739 | + }, |
| 1740 | + } |
| 1741 | + return claim |
| 1742 | + }, |
| 1743 | + }, |
| 1744 | + "too-many-binding-failure-conditions": { |
| 1745 | + wantFailures: field.ErrorList{field.TooMany(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("bindingFailureConditions"), 5, 4)}, |
| 1746 | + oldClaim: validClaim, |
| 1747 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1748 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1749 | + Devices: resource.DeviceAllocationResult{ |
| 1750 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1751 | + Request: goodName, |
| 1752 | + Driver: goodName, |
| 1753 | + Pool: goodName, |
| 1754 | + Device: goodName, |
| 1755 | + AdminAccess: ptr.To(false), |
| 1756 | + BindingConditions: []string{"condition1", "condition2"}, |
| 1757 | + BindingFailureConditions: []string{"condition3", "condition4", "condition5", "condition6", "condition7"}, |
| 1758 | + }}, |
| 1759 | + }, |
| 1760 | + } |
| 1761 | + return claim |
| 1762 | + }, |
| 1763 | + }, |
| 1764 | + "invalid-binding-conditions": { |
| 1765 | + wantFailures: field.ErrorList{field.Invalid(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("bindingConditions").Index(1), "condition2!", conditionValidationErrMessage)}, |
| 1766 | + oldClaim: validClaim, |
| 1767 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1768 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1769 | + Devices: resource.DeviceAllocationResult{ |
| 1770 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1771 | + Request: goodName, |
| 1772 | + Driver: goodName, |
| 1773 | + Pool: goodName, |
| 1774 | + Device: goodName, |
| 1775 | + AdminAccess: ptr.To(false), |
| 1776 | + BindingConditions: []string{"condition1", "condition2!"}, |
| 1777 | + BindingFailureConditions: []string{"condition3", "condition4"}, |
| 1778 | + }}, |
| 1779 | + }, |
| 1780 | + } |
| 1781 | + return claim |
| 1782 | + }, |
| 1783 | + }, |
| 1784 | + "invalid-binding-failure-conditions": { |
| 1785 | + wantFailures: field.ErrorList{field.Invalid(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("bindingFailureConditions").Index(1), "condition4!", conditionValidationErrMessage)}, |
| 1786 | + oldClaim: validClaim, |
| 1787 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1788 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1789 | + Devices: resource.DeviceAllocationResult{ |
| 1790 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1791 | + Request: goodName, |
| 1792 | + Driver: goodName, |
| 1793 | + Pool: goodName, |
| 1794 | + Device: goodName, |
| 1795 | + AdminAccess: ptr.To(false), |
| 1796 | + BindingConditions: []string{"condition1", "condition2"}, |
| 1797 | + BindingFailureConditions: []string{"condition3", "condition4!"}, |
| 1798 | + }}, |
| 1799 | + }, |
| 1800 | + } |
| 1801 | + return claim |
| 1802 | + }, |
| 1803 | + }, |
| 1804 | + "lacking-binding-conditions-claim-has-binding-failure-conditions": { |
| 1805 | + wantFailures: field.ErrorList{field.Invalid(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("bindingConditions"), []string(nil), "bindingConditions are required to use bindingFailureConditions")}, |
| 1806 | + oldClaim: validClaim, |
| 1807 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1808 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1809 | + Devices: resource.DeviceAllocationResult{ |
| 1810 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1811 | + Request: goodName, |
| 1812 | + Driver: goodName, |
| 1813 | + Pool: goodName, |
| 1814 | + Device: goodName, |
| 1815 | + AdminAccess: ptr.To(false), |
| 1816 | + BindingConditions: nil, |
| 1817 | + BindingFailureConditions: []string{"condition3", "condition4"}, |
| 1818 | + }}, |
| 1819 | + }, |
| 1820 | + } |
| 1821 | + return claim |
| 1822 | + }, |
| 1823 | + }, |
| 1824 | + "lacking-binding-failure-conditions-claim-has-binding-conditions": { |
| 1825 | + wantFailures: field.ErrorList{field.Invalid(field.NewPath("status", "allocation", "devices", "results").Index(0).Child("bindingFailureConditions"), []string(nil), "bindingFailureConditions are required to use bindingConditions")}, |
| 1826 | + oldClaim: validClaim, |
| 1827 | + update: func(claim *resource.ResourceClaim) *resource.ResourceClaim { |
| 1828 | + claim.Status.Allocation = &resource.AllocationResult{ |
| 1829 | + Devices: resource.DeviceAllocationResult{ |
| 1830 | + Results: []resource.DeviceRequestAllocationResult{{ |
| 1831 | + Request: goodName, |
| 1832 | + Driver: goodName, |
| 1833 | + Pool: goodName, |
| 1834 | + Device: goodName, |
| 1835 | + AdminAccess: ptr.To(false), |
| 1836 | + BindingConditions: []string{"condition1", "condition2"}, |
| 1837 | + BindingFailureConditions: nil, |
| 1838 | + }}, |
| 1839 | + }, |
| 1840 | + } |
| 1841 | + return claim |
| 1842 | + }, |
| 1843 | + }, |
1704 | 1844 | } |
1705 | 1845 |
|
1706 | 1846 | for name, scenario := range scenarios { |
|
0 commit comments