@@ -102,15 +102,16 @@ func TestIntegrationNetwork_CreateAttached(t *testing.T) {
102102 }
103103
104104 cases := []struct {
105- name string
106- in * []cloudscale.InterfaceRequest
107- expectedIP string
105+ name string
106+ in * []cloudscale.InterfaceRequest
107+ expectedNumNetworks int
108+ expectedIP string
108109 }{
109110 {"Attach by network UUID" , & []cloudscale.InterfaceRequest {
110111 {
111112 Network : network .UUID ,
112113 },
113- }, `192\.168\.42\.[0-9]*` },
114+ }, 1 , `192\.168\.42\.[0-9]*` },
114115 {"Attach by subnet UUID" , & []cloudscale.InterfaceRequest {
115116 {
116117 Addresses : & []cloudscale.AddressRequest {
@@ -119,7 +120,7 @@ func TestIntegrationNetwork_CreateAttached(t *testing.T) {
119120 },
120121 },
121122 },
122- }, `192\.168\.42\.[0-9]*` },
123+ }, 1 , `192\.168\.42\.[0-9]*` },
123124 {"Attach by subnet UUID with predefined IP" , & []cloudscale.InterfaceRequest {
124125 {
125126 Addresses : & []cloudscale.AddressRequest {
@@ -129,7 +130,16 @@ func TestIntegrationNetwork_CreateAttached(t *testing.T) {
129130 },
130131 },
131132 },
132- }, `192\.168\.42\.242` },
133+ }, 1 , `192\.168\.42\.242` },
134+ {"Attach by network UUID without IP (Layer 2)" , & []cloudscale.InterfaceRequest {
135+ {
136+ Network : "public" ,
137+ },
138+ {
139+ Network : network .UUID ,
140+ Addresses : & []cloudscale.AddressRequest {},
141+ },
142+ }, 2 , "" },
133143 }
134144
135145 for _ , tt := range cases {
@@ -151,18 +161,23 @@ func TestIntegrationNetwork_CreateAttached(t *testing.T) {
151161 }
152162 waitUntil ("running" , server .UUID , t )
153163
154- if numNetworks := len (server .Interfaces ); numNetworks != 1 {
155- t .Errorf ("Attatched to number of Networks\n got=%#v\n want=%#v" , numNetworks , 1 )
164+ if numNetworks := len (server .Interfaces ); numNetworks != tt . expectedNumNetworks {
165+ t .Errorf ("Attatched to number of Networks\n got=%#v\n want=%#v" , numNetworks , tt . expectedNumNetworks )
156166 }
157- singleInterface := server .Interfaces [0 ];
158- if singleInterface .Network .UUID != network .UUID {
159- t .Errorf ("Attatched to wrong Network\n got=%#v\n want=%#v" , singleInterface .Network .UUID , network .UUID )
167+ lastNetworkInterface := server .Interfaces [len ( server . Interfaces ) - 1 ];
168+ if lastNetworkInterface .Network .UUID != network .UUID {
169+ t .Errorf ("Attatched to wrong Network\n got=%#v\n want=%#v" , lastNetworkInterface .Network .UUID , network .UUID )
160170 }
161- re := regexp .MustCompile (tt .expectedIP )
162- if ! re .Match ([]byte (singleInterface .Addresses [0 ].Address )) {
163- t .Errorf ("Expected IP regex does not match\n got=%#v\n want=%#v" , singleInterface .Addresses [0 ].Address , tt .expectedIP )
171+ if tt .expectedIP != "" {
172+ re := regexp .MustCompile (tt .expectedIP )
173+ if ! re .Match ([]byte (lastNetworkInterface .Addresses [0 ].Address )) {
174+ t .Errorf ("Expected IP regex does not match\n got=%#v\n want=%#v" , lastNetworkInterface .Addresses [0 ].Address , tt .expectedIP )
175+ }
176+ } else {
177+ if len (lastNetworkInterface .Addresses ) != 0 {
178+ t .Errorf ("Expected no IP addresses\n got=%#v" , len (lastNetworkInterface .Addresses ))
179+ }
164180 }
165-
166181 err = client .Servers .Delete (context .Background (), server .UUID )
167182 if err != nil {
168183 t .Fatalf ("Servers.Delete returned error %s\n " , err )
0 commit comments