Skip to content

Commit 5434684

Browse files
committed
fix tests
1 parent d7dd3fb commit 5434684

File tree

7 files changed

+63
-68
lines changed

7 files changed

+63
-68
lines changed

doc/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11529,13 +11529,6 @@ <h3 id="metalstack.api.v2.Switch">Switch</h3>
1152911529
<td><p>Partition the switch belongs to. </p></td>
1153011530
</tr>
1153111531

11532-
<tr>
11533-
<td>type</td>
11534-
<td><a href="#metalstack.api.v2.SwitchType">SwitchType</a></td>
11535-
<td></td>
11536-
<td><p>Type is the role of the switch. </p></td>
11537-
</tr>
11538-
1153911532
<tr>
1154011533
<td>replace_mode</td>
1154111534
<td><a href="#metalstack.api.v2.SwitchReplaceMode">SwitchReplaceMode</a></td>
@@ -11585,6 +11578,13 @@ <h3 id="metalstack.api.v2.Switch">Switch</h3>
1158511578
<td><p>MachineConnections map machines to the nics they are connected to. </p></td>
1158611579
</tr>
1158711580

11581+
<tr>
11582+
<td>type</td>
11583+
<td><a href="#metalstack.api.v2.SwitchType">SwitchType</a></td>
11584+
<td></td>
11585+
<td><p>Type is the role of the switch. </p></td>
11586+
</tr>
11587+
1158811588
</tbody>
1158911589
</table>
1159011590

go/metalstack/api/v2/switch.pb.go

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/tests/validation/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func validateProtos(t *testing.T, tests prototests) {
2727
t.Errorf("validate error = %v, wantErr %v", err, tt.wantErr)
2828
}
2929
if err != nil && tt.wantErr {
30-
if diff := cmp.Diff(err.Error(), tt.wantErrorMessage); diff != "" {
30+
if diff := cmp.Diff(tt.wantErrorMessage, err.Error()); diff != "" {
3131
t.Errorf("validate error = %v, diff %v", err, diff)
3232
}
3333
}

go/tests/validation/switch_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@ package validation
33
import (
44
"testing"
55

6-
"buf.build/go/protovalidate"
76
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
8-
"github.com/stretchr/testify/require"
97
)
108

119
func TestValidateMACAddress(t *testing.T) {
12-
validator, err := protovalidate.New()
13-
require.NoError(t, err)
14-
1510
tests := prototests{
1611
{
1712
name: "Valid MAC address",
@@ -30,7 +25,7 @@ func TestValidateMACAddress(t *testing.T) {
3025
Identifier: "Eth1/1",
3126
},
3227
wantErr: true,
33-
wantErrorMessage: "validation error:\n - mac: value does not match regex pattern `^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$` [string.pattern]",
28+
wantErrorMessage: "validation error: mac: this string must be a valid macaddress",
3429
},
3530
{
3631
name: "Too short",
@@ -40,7 +35,7 @@ func TestValidateMACAddress(t *testing.T) {
4035
Identifier: "Eth1/1",
4136
},
4237
wantErr: true,
43-
wantErrorMessage: "validation error:\n - mac: value does not match regex pattern `^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$` [string.pattern]",
38+
wantErrorMessage: "validation error: mac: this string must be a valid macaddress",
4439
},
4540
{
4641
name: "Invalid separator",
@@ -50,7 +45,7 @@ func TestValidateMACAddress(t *testing.T) {
5045
Identifier: "Eth1/1",
5146
},
5247
wantErr: true,
53-
wantErrorMessage: "validation error:\n - mac: value does not match regex pattern `^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$` [string.pattern]",
48+
wantErrorMessage: "validation error: mac: this string must be a valid macaddress",
5449
},
5550
{
5651
name: "Invalid character",
@@ -60,7 +55,7 @@ func TestValidateMACAddress(t *testing.T) {
6055
Identifier: "Eth1/1",
6156
},
6257
wantErr: true,
63-
wantErrorMessage: "validation error:\n - mac: value does not match regex pattern `^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$` [string.pattern]",
58+
wantErrorMessage: "validation error: mac: this string must be a valid macaddress",
6459
},
6560
{
6661
name: "Uppercase and lowercase allowed",
@@ -70,9 +65,9 @@ func TestValidateMACAddress(t *testing.T) {
7065
Identifier: "Eth1/1",
7166
},
7267
wantErr: true,
73-
wantErrorMessage: "validation error:\n - mac: value does not match regex pattern `^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$` [string.pattern]",
68+
wantErrorMessage: "validation error: mac: this string must be a valid macaddress",
7469
},
7570
}
7671

77-
validateProtos(t, tests, validator)
72+
validateProtos(t, tests)
7873
}

proto/metalstack/api/v2/switch.proto

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ message Switch {
2525
optional string rack = 4 [(buf.validate.field).string.(metalstack.api.v2.is_name) = true];
2626
// Partition the switch belongs to.
2727
string partition = 5 [(buf.validate.field).string.(metalstack.api.v2.is_partition) = true];
28-
// Type is the role of the switch.
29-
SwitchType type = 6 [(buf.validate.field).enum.defined_only = true];
3028
// ReplaceMode is used to mark a switch ready for replacement.
31-
SwitchReplaceMode replace_mode = 7 [(buf.validate.field).enum.defined_only = true];
29+
SwitchReplaceMode replace_mode = 6 [(buf.validate.field).enum.defined_only = true];
3230
// ManagementIp is the switch's IP for management access.
33-
string management_ip = 8 [(buf.validate.field).string.ip = true];
31+
string management_ip = 7 [(buf.validate.field).string.ip = true];
3432
// ManagementUser is the user name to use for management access.
35-
optional string management_user = 9 [(buf.validate.field).string = {
33+
optional string management_user = 8 [(buf.validate.field).string = {
3634
min_len: 2
3735
max_len: 128
3836
}];
3937
// ConsoleCommand is the command for accessing the switch's console.
40-
optional string console_command = 10 [(buf.validate.field).string = {
38+
optional string console_command = 9 [(buf.validate.field).string = {
4139
min_len: 2
4240
max_len: 128
4341
}];
4442
// Nics are the front panel ports of the switch.
45-
repeated SwitchNic nics = 11;
43+
repeated SwitchNic nics = 10;
4644
// SwitchOs is the OS running on the switch.
47-
SwitchOS os = 12;
45+
SwitchOS os = 11;
4846
// MachineConnections map machines to the nics they are connected to.
49-
repeated MachineConnection machine_connections = 13;
47+
repeated MachineConnection machine_connections = 12;
48+
// Type is the role of the switch.
49+
SwitchType type = 13 [(buf.validate.field).enum.defined_only = true];
5050
}
5151

5252
// SwitchOS holds information about the NOS and versions running on the switch.

0 commit comments

Comments
 (0)