|
1 | 1 | package client_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | "github.com/stretchr/testify/assert" |
| 8 | + "k8s.io/apimachinery/pkg/util/wait" |
7 | 9 |
|
8 | 10 | "github.com/AliyunContainerService/terway/pkg/aliyun/client" |
9 | 11 | "github.com/AliyunContainerService/terway/pkg/aliyun/credential" |
@@ -54,3 +56,145 @@ func TestAPIFacade_CreateNetworkInterface(t *testing.T) { |
54 | 56 | // Test that the facade implements the ENI interface |
55 | 57 | var _ client.ENI = facade |
56 | 58 | } |
| 59 | + |
| 60 | +// ============================================================================== |
| 61 | +// V2 Methods Coverage Tests (Lines 50-156) |
| 62 | +// ============================================================================== |
| 63 | + |
| 64 | +func TestAPIFacade_CreateNetworkInterfaceV2(t *testing.T) { |
| 65 | + clientSet := &credential.ClientMgr{} |
| 66 | + limitConfig := client.LimitConfig{} |
| 67 | + facade := client.NewAPIFacade(clientSet, limitConfig) |
| 68 | + |
| 69 | + // Test unknown backend to achieve coverage without triggering nil pointer |
| 70 | + t.Run("Unknown backend returns not implemented", func(t *testing.T) { |
| 71 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPI(999)) |
| 72 | + _, err := facade.CreateNetworkInterfaceV2(ctx) |
| 73 | + assert.Error(t, err) |
| 74 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 75 | + }) |
| 76 | +} |
| 77 | + |
| 78 | +func TestAPIFacade_DescribeNetworkInterfaceV2(t *testing.T) { |
| 79 | + clientSet := &credential.ClientMgr{} |
| 80 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 81 | + |
| 82 | + tests := []struct { |
| 83 | + name string |
| 84 | + backendAPI client.BackendAPI |
| 85 | + wantErr bool |
| 86 | + }{ |
| 87 | + {"Unknown backend returns not implemented", client.BackendAPI(999), true}, |
| 88 | + } |
| 89 | + |
| 90 | + for _, tt := range tests { |
| 91 | + t.Run(tt.name, func(t *testing.T) { |
| 92 | + ctx := client.SetBackendAPI(context.Background(), tt.backendAPI) |
| 93 | + _, err := facade.DescribeNetworkInterfaceV2(ctx) |
| 94 | + if tt.wantErr { |
| 95 | + assert.Error(t, err) |
| 96 | + } |
| 97 | + }) |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +func TestAPIFacade_AttachNetworkInterfaceV2(t *testing.T) { |
| 102 | + clientSet := &credential.ClientMgr{} |
| 103 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 104 | + |
| 105 | + t.Run("Unknown backend returns not implemented", func(t *testing.T) { |
| 106 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPI(999)) |
| 107 | + err := facade.AttachNetworkInterfaceV2(ctx) |
| 108 | + assert.Error(t, err) |
| 109 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 110 | + }) |
| 111 | +} |
| 112 | + |
| 113 | +func TestAPIFacade_DetachNetworkInterfaceV2(t *testing.T) { |
| 114 | + clientSet := &credential.ClientMgr{} |
| 115 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 116 | + |
| 117 | + t.Run("Unknown backend returns not implemented", func(t *testing.T) { |
| 118 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPI(999)) |
| 119 | + err := facade.DetachNetworkInterfaceV2(ctx) |
| 120 | + assert.Error(t, err) |
| 121 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 122 | + }) |
| 123 | +} |
| 124 | + |
| 125 | +func TestAPIFacade_DeleteNetworkInterfaceV2(t *testing.T) { |
| 126 | + clientSet := &credential.ClientMgr{} |
| 127 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 128 | + |
| 129 | + t.Run("Unknown backend returns not implemented", func(t *testing.T) { |
| 130 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPI(999)) |
| 131 | + err := facade.DeleteNetworkInterfaceV2(ctx, "eni-test") |
| 132 | + assert.Error(t, err) |
| 133 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 134 | + }) |
| 135 | +} |
| 136 | + |
| 137 | +func TestAPIFacade_AssignPrivateIPAddressV2(t *testing.T) { |
| 138 | + clientSet := &credential.ClientMgr{} |
| 139 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 140 | + |
| 141 | + t.Run("EFLO HDENI backend returns not implemented", func(t *testing.T) { |
| 142 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPIEFLOHDENI) |
| 143 | + _, err := facade.AssignPrivateIPAddressV2(ctx) |
| 144 | + assert.Error(t, err) |
| 145 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 146 | + }) |
| 147 | +} |
| 148 | + |
| 149 | +func TestAPIFacade_UnAssignPrivateIPAddressesV2(t *testing.T) { |
| 150 | + clientSet := &credential.ClientMgr{} |
| 151 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 152 | + |
| 153 | + t.Run("EFLO HDENI backend returns not implemented", func(t *testing.T) { |
| 154 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPIEFLOHDENI) |
| 155 | + err := facade.UnAssignPrivateIPAddressesV2(ctx, "eni-test", []client.IPSet{}) |
| 156 | + assert.Error(t, err) |
| 157 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 158 | + }) |
| 159 | +} |
| 160 | + |
| 161 | +func TestAPIFacade_AssignIpv6AddressesV2(t *testing.T) { |
| 162 | + clientSet := &credential.ClientMgr{} |
| 163 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 164 | + |
| 165 | + t.Run("EFLO backend returns not implemented", func(t *testing.T) { |
| 166 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPIEFLO) |
| 167 | + _, err := facade.AssignIpv6AddressesV2(ctx) |
| 168 | + assert.Error(t, err) |
| 169 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 170 | + }) |
| 171 | +} |
| 172 | + |
| 173 | +func TestAPIFacade_UnAssignIpv6AddressesV2(t *testing.T) { |
| 174 | + clientSet := &credential.ClientMgr{} |
| 175 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 176 | + |
| 177 | + t.Run("EFLO backend returns not implemented", func(t *testing.T) { |
| 178 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPIEFLO) |
| 179 | + err := facade.UnAssignIpv6AddressesV2(ctx, "eni-test", []client.IPSet{}) |
| 180 | + assert.Error(t, err) |
| 181 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 182 | + }) |
| 183 | +} |
| 184 | + |
| 185 | +func TestAPIFacade_WaitForNetworkInterfaceV2(t *testing.T) { |
| 186 | + clientSet := &credential.ClientMgr{} |
| 187 | + facade := client.NewAPIFacade(clientSet, client.LimitConfig{}) |
| 188 | + |
| 189 | + backoff := wait.Backoff{ |
| 190 | + Steps: 1, |
| 191 | + Duration: 1, |
| 192 | + } |
| 193 | + |
| 194 | + t.Run("EFLO HDENI backend returns not implemented", func(t *testing.T) { |
| 195 | + ctx := client.SetBackendAPI(context.Background(), client.BackendAPIEFLOHDENI) |
| 196 | + _, err := facade.WaitForNetworkInterfaceV2(ctx, "eni-test", "Available", backoff, false) |
| 197 | + assert.Error(t, err) |
| 198 | + assert.Equal(t, client.ErrNotImplemented, err) |
| 199 | + }) |
| 200 | +} |
0 commit comments