From 49ad3d20f8d1d892e8b1294bcbdde114f07f73c8 Mon Sep 17 00:00:00 2001 From: sylwiaszunejko Date: Wed, 11 Dec 2024 13:09:46 +0100 Subject: [PATCH] Add ParseUUIDMust for tests --- conn_test.go | 16 +++++----------- ring_describer_test.go | 24 +++++++----------------- uuid.go | 8 ++++++++ uuid_test.go | 2 +- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/conn_test.go b/conn_test.go index 9b75e02dd..f1bdd4338 100644 --- a/conn_test.go +++ b/conn_test.go @@ -1398,17 +1398,11 @@ func (srv *TestServer) readFrame(conn net.Conn) (*framer, error) { } func TestGetSchemaAgreement(t *testing.T) { - host_id1, _ := ParseUUID("b2035fd9-e0ca-4857-8c45-e63c00fb7c43") - host_id2, _ := ParseUUID("4b21ee4c-acea-4267-8e20-aaed5361a0dd") - host_id3, _ := ParseUUID("dfef4a22-b8d8-47e9-aee5-8c19d4b7a9e3") - - schema_version1, _ := ParseUUID("af810386-a694-11ef-81fa-3aea73156247") - schema_version2, _ := ParseUUID("875a938a-a695-11ef-4314-85c8ef0ebaa2") - + schema_version1 := ParseUUIDMust("af810386-a694-11ef-81fa-3aea73156247") peersRows := []map[string]interface{}{ { "data_center": "datacenter1", - "host_id": host_id1, + "host_id": ParseUUIDMust("b2035fd9-e0ca-4857-8c45-e63c00fb7c43"), "peer": "127.0.0.3", "preferred_ip": "127.0.0.3", "rack": "rack1", @@ -1419,7 +1413,7 @@ func TestGetSchemaAgreement(t *testing.T) { }, { "data_center": "datacenter1", - "host_id": host_id2, + "host_id": ParseUUIDMust("4b21ee4c-acea-4267-8e20-aaed5361a0dd"), "peer": "127.0.0.2", "preferred_ip": "127.0.0.2", "rack": "rack1", @@ -1430,13 +1424,13 @@ func TestGetSchemaAgreement(t *testing.T) { }, { "data_center": "datacenter2", - "host_id": host_id3, + "host_id": ParseUUIDMust("dfef4a22-b8d8-47e9-aee5-8c19d4b7a9e3"), "peer": "127.0.0.5", "preferred_ip": "127.0.0.5", "rack": "rack1", "release_version": "3.0.8", "rpc_address": "127.0.0.5", - "schema_version": schema_version2, + "schema_version": ParseUUIDMust("875a938a-a695-11ef-4314-85c8ef0ebaa2"), "tokens": []string{}, }, } diff --git a/ring_describer_test.go b/ring_describer_test.go index dc90f7d6b..4f02b5fb3 100644 --- a/ring_describer_test.go +++ b/ring_describer_test.go @@ -13,16 +13,12 @@ import ( ) func TestGetClusterPeerInfoZeroToken(t *testing.T) { - host_id1, _ := ParseUUID("b2035fd9-e0ca-4857-8c45-e63c00fb7c43") - host_id2, _ := ParseUUID("4b21ee4c-acea-4267-8e20-aaed5361a0dd") - host_id3, _ := ParseUUID("dfef4a22-b8d8-47e9-aee5-8c19d4b7a9e3") - - schema_version1, _ := ParseUUID("af810386-a694-11ef-81fa-3aea73156247") + schema_version1 := ParseUUIDMust("af810386-a694-11ef-81fa-3aea73156247") peersRows := []map[string]interface{}{ { "data_center": "datacenter1", - "host_id": host_id1, + "host_id": ParseUUIDMust("b2035fd9-e0ca-4857-8c45-e63c00fb7c43"), "peer": "127.0.0.3", "preferred_ip": "127.0.0.3", "rack": "rack1", @@ -33,7 +29,7 @@ func TestGetClusterPeerInfoZeroToken(t *testing.T) { }, { "data_center": "datacenter1", - "host_id": host_id2, + "host_id": ParseUUIDMust("4b21ee4c-acea-4267-8e20-aaed5361a0dd"), "peer": "127.0.0.2", "preferred_ip": "127.0.0.2", "rack": "rack1", @@ -44,7 +40,7 @@ func TestGetClusterPeerInfoZeroToken(t *testing.T) { }, { "data_center": "datacenter2", - "host_id": host_id3, + "host_id": ParseUUIDMust("dfef4a22-b8d8-47e9-aee5-8c19d4b7a9e3"), "peer": "127.0.0.5", "preferred_ip": "127.0.0.5", "rack": "rack1", @@ -265,15 +261,9 @@ var systemPeersResultMetadata = resultMetadata{ } func (*mockConnection) querySystem(ctx context.Context, query string) *Iter { - host_id, _ := ParseUUID("045859a7-6b9f-4efd-a5e7-acd64a295e13") - schema_version, _ := ParseUUID("daf4df2c-b708-11ef-5c25-3004361afd71") - localData := []interface{}{"local", "COMPLETED", net.IPv4(192, 168, 100, 12), "", "3.3.1", "datacenter1", 1733834239, host_id, net.IPv4(192, 168, 100, 12), "4", "org.apache.cassandra.dht.Murmur3Partitioner", "rack1", "3.0.8", net.IPv4(192, 168, 100, 12), schema_version, "", []string{}, map[UUID]byte{}} - - host_id1, _ := ParseUUID("b953309f-6e68-41f2-baf5-0e60da317a9c") - host_id2, _ := ParseUUID("8269e111-ea38-44bd-a73f-9d3d12cfaf78") - schema_version, _ = ParseUUID("b6ed5bde-b318-11ef-8f58-aeba19e31273") - peerData1 := []interface{}{net.IPv4(192, 168, 100, 13), "datacenter1", host_id1, net.IP{}, "rack1", "3.0.8", net.IPv4(192, 168, 100, 13), schema_version, "", []string{"-1032311531684407545", "-1112089412567859825"}} - peerData2 := []interface{}{net.IPv4(192, 168, 100, 14), "datacenter1", host_id2, net.IP{}, "rack1", "3.0.8", net.IPv4(192, 168, 100, 14), schema_version, "", []string{}} + localData := []interface{}{"local", "COMPLETED", net.IPv4(192, 168, 100, 12), "", "3.3.1", "datacenter1", 1733834239, ParseUUIDMust("045859a7-6b9f-4efd-a5e7-acd64a295e13"), net.IPv4(192, 168, 100, 12), "4", "org.apache.cassandra.dht.Murmur3Partitioner", "rack1", "3.0.8", net.IPv4(192, 168, 100, 12), ParseUUIDMust("daf4df2c-b708-11ef-5c25-3004361afd71"), "", []string{}, map[UUID]byte{}} + peerData1 := []interface{}{net.IPv4(192, 168, 100, 13), "datacenter1", ParseUUIDMust("b953309f-6e68-41f2-baf5-0e60da317a9c"), net.IP{}, "rack1", "3.0.8", net.IPv4(192, 168, 100, 13), ParseUUIDMust("b6ed5bde-b318-11ef-8f58-aeba19e31273"), "", []string{"-1032311531684407545", "-1112089412567859825"}} + peerData2 := []interface{}{net.IPv4(192, 168, 100, 14), "datacenter1", ParseUUIDMust("8269e111-ea38-44bd-a73f-9d3d12cfaf78"), net.IP{}, "rack1", "3.0.8", net.IPv4(192, 168, 100, 14), ParseUUIDMust("b6ed5bde-b318-11ef-8f58-aeba19e31273"), "", []string{}} if query == "SELECT * FROM system.local WHERE key='local'" { return &Iter{ diff --git a/uuid.go b/uuid.go index acdd81f94..9bd966531 100644 --- a/uuid.go +++ b/uuid.go @@ -85,6 +85,14 @@ func ParseUUID(input string) (UUID, error) { return u, nil } +func ParseUUIDMust(input string) UUID { + uuid, err := ParseUUID(input) + if err != nil { + panic(err) + } + return uuid +} + // UUIDFromBytes converts a raw byte slice to an UUID. func UUIDFromBytes(input []byte) (UUID, error) { var u UUID diff --git a/uuid_test.go b/uuid_test.go index 65a660953..3e6e1b2f8 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -168,7 +168,7 @@ func TestTimeUUIDWith(t *testing.T) { } func TestParseUUID(t *testing.T) { - uuid, _ := ParseUUID("486f3a88-775b-11e3-ae07-d231feb1dc81") + uuid := ParseUUIDMust("486f3a88-775b-11e3-ae07-d231feb1dc81") if uuid.Time() != time.Date(2014, 1, 7, 5, 19, 29, 222516000, time.UTC) { t.Errorf("Expected date of 1/7/2014 at 5:19:29.222516, got %v", uuid.Time()) }