From cb99da8f9b6dd54dd718dd55f4983efdbab22f46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Aug 2023 21:17:30 +0000 Subject: [PATCH 1/3] feat(deps): bump github.com/go-kit/kit from 0.12.0 to 0.13.0 (#133) Bumps [github.com/go-kit/kit](https://github.com/go-kit/kit) from 0.12.0 to 0.13.0. - [Release notes](https://github.com/go-kit/kit/releases) - [Commits](https://github.com/go-kit/kit/compare/v0.12.0...v0.13.0) --- updated-dependencies: - dependency-name: github.com/go-kit/kit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a99d83e..3033aaf 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/davecgh/go-spew v1.1.1 - github.com/go-kit/kit v0.12.0 + github.com/go-kit/kit v0.13.0 github.com/go-kit/log v0.2.1 github.com/google/uuid v1.3.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 32c05eb..b436d71 100644 --- a/go.sum +++ b/go.sum @@ -170,8 +170,8 @@ github.com/go-ini/ini v1.36.1-0.20180420150025-bda519ae5f4c/go.mod h1:ByCAeIL28u github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= -github.com/go-kit/kit v0.12.0 h1:e4o3o3IsBfAKQh5Qbbiqyfu97Ku7jrO/JbohvztANh4= -github.com/go-kit/kit v0.12.0/go.mod h1:lHd+EkCZPIwYItmGDDRdhinkzX2A1sj+M9biaEaizzs= +github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU= +github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg= github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc= From 9de4923ee5c50d72a782540bd140f45a954804cd Mon Sep 17 00:00:00 2001 From: schmidtw Date: Fri, 22 Sep 2023 15:36:45 -0700 Subject: [PATCH 2/3] Add two DeviceID helper functions so the prefix:id are always uniformly split when that is needed. --- id.go | 23 ++++++++++++ id_test.go | 101 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 16 deletions(-) diff --git a/id.go b/id.go index 7fba246..4b22bac 100644 --- a/id.go +++ b/id.go @@ -52,6 +52,29 @@ func (id DeviceID) Bytes() []byte { return []byte(id) } +// String is a convenience function to obtain the string representation of the +// prefix portion of the ID. +func (id DeviceID) Prefix() string { + prefix, _ := id.split() + return prefix +} + +// ID is a convenience function to obtain the string representation of the +// identifier portion of the ID. +func (id DeviceID) ID() string { + _, idPart := id.split() + return idPart +} + +func (id DeviceID) split() (prefix, idPart string) { + parts := strings.SplitN(string(id), ":", 2) + if len(parts) != 2 { + return parts[0], "" + } + + return parts[0], parts[1] +} + // ParseID parses a raw device name into a canonicalized identifier. func ParseDeviceID(deviceName string) (DeviceID, error) { match := DeviceIDPattern.FindStringSubmatch(deviceName) diff --git a/id_test.go b/id_test.go index 8e3d50e..135205a 100644 --- a/id_test.go +++ b/id_test.go @@ -28,24 +28,91 @@ func TestParseDeviceID(t *testing.T) { testData := []struct { id string expected DeviceID + prefix string + literalID string expectsError bool }{ - {"MAC:11:22:33:44:55:66", "mac:112233445566", false}, - {"MAC:11aaBB445566", "mac:11aabb445566", false}, - {"mac:11-aa-BB-44-55-66", "mac:11aabb445566", false}, - {"mac:11,aa,BB,44,55,66", "mac:11aabb445566", false}, - {"uuid:anything Goes!", "uuid:anything Goes!", false}, - {"dns:anything Goes!", "dns:anything Goes!", false}, - {"serial:1234", "serial:1234", false}, - {"mac:11-aa-BB-44-55-66/service", "mac:11aabb445566", false}, - {"mac:11-aa-BB-44-55-66/service/", "mac:11aabb445566", false}, - {"mac:11-aa-BB-44-55-66/service/ignoreMe", "mac:11aabb445566", false}, - {"mac:11-aa-BB-44-55-66/service/foo/bar", "mac:11aabb445566", false}, - {"invalid:a-BB-44-55", "", true}, - {"mac:11-aa-BB-44-55", "", true}, - {"MAC:invalid45566", "", true}, - {"mac:481d70187fef", "mac:481d70187fef", false}, - {"mac:481d70187fef/parodus/tag/test0", "mac:481d70187fef", false}, + { + id: "MAC:11:22:33:44:55:66", + expected: "mac:112233445566", + prefix: "mac", + literalID: "112233445566", + }, { + id: "MAC:11aaBB445566", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "mac:11-aa-BB-44-55-66", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "mac:11,aa,BB,44,55,66", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "uuid:anything Goes!", + expected: "uuid:anything Goes!", + prefix: "uuid", + literalID: "anything Goes!", + }, { + id: "dns:anything Goes!", + expected: "dns:anything Goes!", + prefix: "dns", + literalID: "anything Goes!", + }, { + id: "serial:1234", + expected: "serial:1234", + prefix: "serial", + literalID: "1234", + }, { + id: "mac:11-aa-BB-44-55-66/service", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "mac:11-aa-BB-44-55-66/service/", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "MAC:11-aa-BB-44-55-66/service/ignoreMe", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "mac:11-aa-BB-44-55-66/service/foo/bar", + expected: "mac:11aabb445566", + prefix: "mac", + literalID: "11aabb445566", + }, { + id: "invalid:a-BB-44-55", + expectsError: true, + }, { + id: "mac:11-aa-BB-44-55", + expectsError: true, + }, { + id: "MAC:invalid45566", + expectsError: true, + }, { + id: "invalid:random stuff", + expectsError: true, + }, { + id: "mac:11223344556w", + expectsError: true, + }, { + id: "mac:481d70187fef", + expected: "mac:481d70187fef", + prefix: "mac", + literalID: "481d70187fef", + }, { + id: "mac:481d70187fef/parodus/tag/test0", + expected: "mac:481d70187fef", + prefix: "mac", + literalID: "481d70187fef", + }, } for _, record := range testData { @@ -54,6 +121,8 @@ func TestParseDeviceID(t *testing.T) { assert.Equal(record.expected, id) assert.Equal(record.expectsError, err != nil) assert.Equal([]byte(record.expected), id.Bytes()) + assert.Equal(record.prefix, id.Prefix()) + assert.Equal(record.literalID, id.ID()) }) } } From 3e55fcd58b466156c1f8d87fd04cc63fc062ee8d Mon Sep 17 00:00:00 2001 From: schmidtw Date: Fri, 22 Sep 2023 16:16:11 -0700 Subject: [PATCH 3/3] Fix the newly identified lint issues. --- wrpclient/wrpclient_test.go | 4 +++- wrphttp/headers.go | 2 +- wrphttp/headers_test.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wrpclient/wrpclient_test.go b/wrpclient/wrpclient_test.go index 49c816a..f803875 100644 --- a/wrpclient/wrpclient_test.go +++ b/wrpclient/wrpclient_test.go @@ -173,7 +173,9 @@ func TestSendWRP(t *testing.T) { client.httpClient = m } - err = client.SendWRP(ctx, &tc.response, &tc.request) + response := tc.response + request := tc.request + err = client.SendWRP(ctx, &response, &request) if tc.useMockHTTPClient { m.AssertExpectations(t) } diff --git a/wrphttp/headers.go b/wrphttp/headers.go index fa8f45c..151d6b4 100644 --- a/wrphttp/headers.go +++ b/wrphttp/headers.go @@ -31,7 +31,7 @@ import ( // Constant HTTP header strings representing WRP fields const ( MessageTypeHeader = "X-Xmidt-Message-Type" - TransactionUuidHeader = "X-Xmidt-Transaction-Uuid" + TransactionUuidHeader = "X-Xmidt-Transaction-Uuid" // nolint:gosec StatusHeader = "X-Xmidt-Status" RequestDeliveryResponseHeader = "X-Xmidt-Request-Delivery-Response" IncludeSpansHeader = "X-Xmidt-Include-Spans" diff --git a/wrphttp/headers_test.go b/wrphttp/headers_test.go index d74c737..228732b 100644 --- a/wrphttp/headers_test.go +++ b/wrphttp/headers_test.go @@ -400,7 +400,8 @@ func TestAddMessageHeaders(t *testing.T) { expected := record.expected actual := make(http.Header) - AddMessageHeaders(actual, &record.message) + message := record.message + AddMessageHeaders(actual, &message) for _, header := range regularHeaders { assert.Equal(expected[header], actual[header])