diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a98ec95..307484d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [1.19.x, 1.20.x, 1.21.x] + go-version: [1.20.x, 1.21.x, 1.22.x] steps: - name: checkout uses: actions/checkout@v4 @@ -32,5 +32,5 @@ jobs: BUF_TOKEN: ${{ secrets.BUF_TOKEN }} run: make test - name: lint - if: matrix.go-version == '1.21.x' + if: matrix.go-version == '1.22.x' run: make lint diff --git a/.golangci.yml b/.golangci.yml index 3902a3e..76eecbd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -34,6 +34,7 @@ linters: - golint # deprecated by Go team - gomnd # some unnamed constants are okay - ifshort # deprecated by author + - inamedparam # convention is not followed - interfacer # deprecated by author - ireturn # "accept interfaces, return structs" isn't ironclad - lll # don't want hard limits for line length diff --git a/LICENSE b/LICENSE index f308f8b..3caecb4 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2023 Buf Technologies, Inc. + Copyright 2023-2024 Buf Technologies, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index d7e6faa..ffe59d3 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,12 @@ MAKEFLAGS += --warn-undefined-variables MAKEFLAGS += --no-builtin-rules MAKEFLAGS += --no-print-directory BIN := .tmp/bin -COPYRIGHT_YEARS := 2023 +COPYRIGHT_YEARS := 2023-2024 LICENSE_IGNORE := -e internal/testdata/ # Set to use a different compiler. For example, `GO=go1.18rc1 make test`. GO ?= go -BUF_VERSION ?= v1.26.1 -GOLANGCI_LINT_VERSION ?= v1.54.1 +BUF_VERSION ?= v1.29.0 +GOLANGCI_LINT_VERSION ?= v1.56.2 .PHONY: help help: ## Describe useful make targets diff --git a/cache.go b/cache.go index a28b66b..76a4d56 100644 --- a/cache.go +++ b/cache.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ func decodeForCache(data []byte) (*prototransformv1alpha1.CacheEntry, error) { } func isCorrectCacheEntry(entry *prototransformv1alpha1.CacheEntry, schemaID string, syms []string) bool { - return entry.Id == schemaID && isSuperSet(entry.IncludedSymbols, syms) + return entry.GetId() == schemaID && isSuperSet(entry.GetIncludedSymbols(), syms) } func isSuperSet(have, want []string) bool { diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go index 32ec64e..9dbbca9 100644 --- a/cache/filecache/filecache.go +++ b/cache/filecache/filecache.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cache/filecache/filecache_test.go b/cache/filecache/filecache_test.go index e7bf00d..9cbc9ac 100644 --- a/cache/filecache/filecache_test.go +++ b/cache/filecache/filecache_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -174,7 +174,7 @@ func TestSanitize(t *testing.T) { func checkFiles(t *testing.T, dir string, mode fs.FileMode, names map[string]struct{}) { t.Helper() err := fs.WalkDir(os.DirFS(dir), ".", func(path string, dirEntry fs.DirEntry, err error) error { - if !assert.NoError(t, err) { + if !assert.NoError(t, err) { //nolint:testifylint return nil } if dirEntry.IsDir() { @@ -190,7 +190,7 @@ func checkFiles(t *testing.T, dir string, mode fs.FileMode, names map[string]str } delete(names, path) info, err := dirEntry.Info() - if !assert.NoErrorf(t, err, "failed to get file info for %s", path) { + if !assert.NoErrorf(t, err, "failed to get file info for %s", path) { //nolint:testifylint return nil } assert.Equal(t, mode, info.Mode()) diff --git a/cache/internal/cachetesting/cachetesting.go b/cache/internal/cachetesting/cachetesting.go index de13b77..0e074ae 100644 --- a/cache/internal/cachetesting/cachetesting.go +++ b/cache/internal/cachetesting/cachetesting.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cache/memcache/memcache.go b/cache/memcache/memcache.go index 35fc6dc..ea7e24b 100644 --- a/cache/memcache/memcache.go +++ b/cache/memcache/memcache.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cache/memcache/memcache_test.go b/cache/memcache/memcache_test.go index 80695e2..fe09ca0 100644 --- a/cache/memcache/memcache_test.go +++ b/cache/memcache/memcache_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cache/rediscache/rediscache.go b/cache/rediscache/rediscache.go index 4cce6c8..6f147b3 100644 --- a/cache/rediscache/rediscache.go +++ b/cache/rediscache/rediscache.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cache/rediscache/rediscache_test.go b/cache/rediscache/rediscache_test.go index dc35a7a..3c96d6d 100644 --- a/cache/rediscache/rediscache_test.go +++ b/cache/rediscache/rediscache_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cache_test.go b/cache_test.go index 0adb067..3232a07 100644 --- a/cache_test.go +++ b/cache_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/config.go b/config.go index f597775..c1b1bfe 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ package prototransform import ( + "errors" "fmt" "time" @@ -83,22 +84,22 @@ type SchemaWatcherConfig struct { func (c *SchemaWatcherConfig) validate() error { if c.SchemaPoller == nil { - return fmt.Errorf("schema poller not provided") + return errors.New("schema poller not provided") } if c.PollingPeriod < 0 { - return fmt.Errorf("polling period duration cannot be negative") + return errors.New("polling period duration cannot be negative") } if c.Jitter < 0 { - return fmt.Errorf("jitter cannot be negative") + return errors.New("jitter cannot be negative") } if c.Jitter > 1.0 { - return fmt.Errorf("jitter cannot be greater than 1.0 (100%%)") + return errors.New("jitter cannot be greater than 1.0 (100%)") } if c.Leaser != nil && c.Cache == nil { - return fmt.Errorf("leaser config should only be present when cache config also present") + return errors.New("leaser config should only be present when cache config also present") } if c.Leaser != nil && c.CurrentProcess != nil && len(c.CurrentProcess) == 0 { - return fmt.Errorf("current process is empty but not nil; leave nil or set to non-empty value") + return errors.New("current process is empty but not nil; leave nil or set to non-empty value") } for _, sym := range c.IncludeSymbols { if sym == "" { diff --git a/converter.go b/converter.go index 1ef5c86..e1d6f9b 100644 --- a/converter.go +++ b/converter.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/converter_test.go b/converter_test.go index c069e20..ada6fa8 100644 --- a/converter_test.go +++ b/converter_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ import ( func TestSchemaService_ConvertMessage(t *testing.T) { t.Parallel() // create schema for message to convert - sourceFile := fakeFileDescriptorSet().File[0] + sourceFile := fakeFileDescriptorSet().GetFile()[0] // create test message fileDescriptor, err := protodesc.NewFile(sourceFile, nil) diff --git a/doc.go b/doc.go index 2fa0338..3620bf5 100644 --- a/doc.go +++ b/doc.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/example_test.go b/example_test.go index 8b89247..5fe7a9c 100644 --- a/example_test.go +++ b/example_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/filter.go b/filter.go index 7f866b4..5fd22aa 100644 --- a/filter.go +++ b/filter.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -90,7 +90,7 @@ func redactList(value protoreflect.Value, redaction func(protoreflect.FieldDescr } func redactMap(value protoreflect.Value, redaction func(protoreflect.FieldDescriptor) bool) { - value.Map().Range(func(mapKey protoreflect.MapKey, mapValue protoreflect.Value) bool { + value.Map().Range(func(_ protoreflect.MapKey, mapValue protoreflect.Value) bool { redactMessage(mapValue.Message(), redaction) return true }) diff --git a/filter_test.go b/filter_test.go index 34622ef..a5bf304 100644 --- a/filter_test.go +++ b/filter_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/format.go b/format.go index d948b3d..eb28417 100644 --- a/format.go +++ b/format.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/go.mod b/go.mod index a9d54b2..84bbcc3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/bufbuild/prototransform -go 1.19 +go 1.20 require ( buf.build/gen/go/bufbuild/reflect/connectrpc/go v1.14.0-20240117202343-bf8f65e8876c.1 diff --git a/internal/proto/buf/prototransform/v1alpha1/cache.proto b/internal/proto/buf/prototransform/v1alpha1/cache.proto index e6c93a4..a9f92ca 100644 --- a/internal/proto/buf/prototransform/v1alpha1/cache.proto +++ b/internal/proto/buf/prototransform/v1alpha1/cache.proto @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/internal/proto/buf/prototransform/v1alpha1/lease.proto b/internal/proto/buf/prototransform/v1alpha1/lease.proto index 7f2392f..9594f1b 100644 --- a/internal/proto/buf/prototransform/v1alpha1/lease.proto +++ b/internal/proto/buf/prototransform/v1alpha1/lease.proto @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/internal/proto/gen/buf/prototransform/v1alpha1/cache.pb.go b/internal/proto/gen/buf/prototransform/v1alpha1/cache.pb.go index 6979fbb..cae41a1 100644 --- a/internal/proto/gen/buf/prototransform/v1alpha1/cache.pb.go +++ b/internal/proto/gen/buf/prototransform/v1alpha1/cache.pb.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/internal/proto/gen/buf/prototransform/v1alpha1/lease.pb.go b/internal/proto/gen/buf/prototransform/v1alpha1/lease.pb.go index 104bf7d..f751c11 100644 --- a/internal/proto/gen/buf/prototransform/v1alpha1/lease.pb.go +++ b/internal/proto/gen/buf/prototransform/v1alpha1/lease.pb.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/jitter.go b/jitter.go index aca3a2a..d7eb719 100644 --- a/jitter.go +++ b/jitter.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/jitter_test.go b/jitter_test.go index fb93c48..1f47aee 100644 --- a/jitter_test.go +++ b/jitter_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser.go b/leaser.go index f673f82..37bbcb6 100644 --- a/leaser.go +++ b/leaser.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser/internal/leasertesting/leasertesting.go b/leaser/internal/leasertesting/leasertesting.go index 36ba18c..56d0ff7 100644 --- a/leaser/internal/leasertesting/leasertesting.go +++ b/leaser/internal/leasertesting/leasertesting.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser/memcacheleaser/memcacheleaser.go b/leaser/memcacheleaser/memcacheleaser.go index 7cf5b96..0aab155 100644 --- a/leaser/memcacheleaser/memcacheleaser.go +++ b/leaser/memcacheleaser/memcacheleaser.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser/memcacheleaser/memcacheleaser_test.go b/leaser/memcacheleaser/memcacheleaser_test.go index 6e087f0..f446f3b 100644 --- a/leaser/memcacheleaser/memcacheleaser_test.go +++ b/leaser/memcacheleaser/memcacheleaser_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser/polling_leaser.go b/leaser/polling_leaser.go index a0fd746..ab3c548 100644 --- a/leaser/polling_leaser.go +++ b/leaser/polling_leaser.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser/redisleaser/redisleaser.go b/leaser/redisleaser/redisleaser.go index c1d2b8d..4f26d19 100644 --- a/leaser/redisleaser/redisleaser.go +++ b/leaser/redisleaser/redisleaser.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/leaser/redisleaser/redisleaser_test.go b/leaser/redisleaser/redisleaser_test.go index 62592aa..6a8f2fc 100644 --- a/leaser/redisleaser/redisleaser_test.go +++ b/leaser/redisleaser/redisleaser_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/reflect_client.go b/reflect_client.go index 2875833..d032e04 100644 --- a/reflect_client.go +++ b/reflect_client.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package prototransform import ( "context" + "errors" "fmt" "net/http" "os" @@ -49,7 +50,7 @@ func NewDefaultFileDescriptorSetServiceClient(token string) reflectv1beta1connec connect.UnaryInterceptorFunc(func(call connect.UnaryFunc) connect.UnaryFunc { return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) { // decorate user-agent with the name of the package - userAgent := fmt.Sprintf("%s prototransform-go", req.Header().Get("User-Agent")) + userAgent := req.Header().Get("User-Agent") + " prototransform-go" req.Header().Set("User-Agent", userAgent) return call(ctx, req) } @@ -68,7 +69,7 @@ func NewDefaultFileDescriptorSetServiceClient(token string) reflectv1beta1connec // // To get a token from the environment (e.g. BUF_TOKEN env var), see BufTokenFromEnvironment. func NewAuthInterceptor(token string) connect.Interceptor { - bearerAuthValue := fmt.Sprintf("Bearer %s", token) + bearerAuthValue := "Bearer " + token return connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc { return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { request.Header().Set("Authorization", bearerAuthValue) @@ -84,7 +85,7 @@ func BufTokenFromEnvironment(moduleRef string) (string, error) { parts := strings.SplitN(moduleRef, "/", 2) envBufToken := os.Getenv("BUF_TOKEN") if envBufToken == "" { - return "", fmt.Errorf("no BUF_TOKEN environment variable set") + return "", errors.New("no BUF_TOKEN environment variable set") } tok := parseBufToken(envBufToken, parts[0]) if tok == "" { diff --git a/reflect_client_test.go b/reflect_client_test.go index f5fe2b2..070984e 100644 --- a/reflect_client_test.go +++ b/reflect_client_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -71,7 +71,7 @@ func TestReflectClientLargeRequest(t *testing.T) { // downloading the entire response. resp, err := getFileDescriptorSet(ctx, client, req) require.NoError(t, err) - require.GreaterOrEqual(t, len(resp.Msg.FileDescriptorSet.File), 42) + require.GreaterOrEqual(t, len(resp.Msg.GetFileDescriptorSet().GetFile()), 42) // If we ask for one fewer type, we should be below the limit and get back // a "not modified" response code instead of a response body. diff --git a/resolver.go b/resolver.go index c506c4d..aff783c 100644 --- a/resolver.go +++ b/resolver.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ type resolver struct { func newResolver(fileDescriptors *descriptorpb.FileDescriptorSet) (*resolver, error) { var result resolver // TODO(TCN-925): maybe should reparse unrecognized fields in fileDescriptors after creating resolver? - if len(fileDescriptors.File) == 0 { + if len(fileDescriptors.GetFile()) == 0 { return &result, nil } files, err := protodesc.FileOptions{AllowUnresolvable: true}.NewFiles(fileDescriptors) diff --git a/schema_poller.go b/schema_poller.go index b53ca45..0ba9ce8 100644 --- a/schema_poller.go +++ b/schema_poller.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -89,7 +89,7 @@ func (b *bufReflectPoller) GetSchema(ctx context.Context, symbols []string, curr } return nil, "", err } - return resp.Msg.FileDescriptorSet, resp.Msg.Version, err + return resp.Msg.GetFileDescriptorSet(), resp.Msg.GetVersion(), err } func (b *bufReflectPoller) GetSchemaID() string { diff --git a/schema_watcher.go b/schema_watcher.go index 34fcd62..f14126c 100644 --- a/schema_watcher.go +++ b/schema_watcher.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/schema_watcher_errors_go119.go b/schema_watcher_errors_go119.go index 4515259..2e6f16d 100644 --- a/schema_watcher_errors_go119.go +++ b/schema_watcher_errors_go119.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/schema_watcher_errors_go120.go b/schema_watcher_errors_go120.go index fca920a..b2eba05 100644 --- a/schema_watcher_errors_go120.go +++ b/schema_watcher_errors_go120.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/schema_watcher_test.go b/schema_watcher_test.go index 6c96946..a0cb7ca 100644 --- a/schema_watcher_test.go +++ b/schema_watcher_test.go @@ -1,4 +1,4 @@ -// Copyright 2023 Buf Technologies, Inc. +// Copyright 2023-2024 Buf Technologies, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ func TestNewSchemaWatcher(t *testing.T) { config := &SchemaWatcherConfig{} got, err := NewSchemaWatcher(ctx, config) require.Error(t, err) - assert.EqualError(t, err, "schema poller not provided") + require.EqualError(t, err, "schema poller not provided") assert.Nil(t, got) }) t.Run("polling period negative", func(t *testing.T) { @@ -55,7 +55,7 @@ func TestNewSchemaWatcher(t *testing.T) { } got, err := NewSchemaWatcher(ctx, config) require.Error(t, err) - assert.EqualError(t, err, "polling period duration cannot be negative") + require.EqualError(t, err, "polling period duration cannot be negative") assert.Nil(t, got) }) t.Run("jitter negative", func(t *testing.T) { @@ -66,7 +66,7 @@ func TestNewSchemaWatcher(t *testing.T) { } got, err := NewSchemaWatcher(ctx, config) require.Error(t, err) - assert.EqualError(t, err, "jitter cannot be negative") + require.EqualError(t, err, "jitter cannot be negative") assert.Nil(t, got) }) t.Run("jitter > 1", func(t *testing.T) { @@ -77,7 +77,7 @@ func TestNewSchemaWatcher(t *testing.T) { } got, err := NewSchemaWatcher(ctx, config) require.Error(t, err) - assert.EqualError(t, err, "jitter cannot be greater than 1.0 (100%)") + require.EqualError(t, err, "jitter cannot be greater than 1.0 (100%)") assert.Nil(t, got) }) t.Run("invalid symbol name", func(t *testing.T) { @@ -88,7 +88,7 @@ func TestNewSchemaWatcher(t *testing.T) { } got, err := NewSchemaWatcher(ctx, config) require.Error(t, err) - assert.EqualError(t, err, `"$poop" is not a valid symbol name`) + require.EqualError(t, err, `"$poop" is not a valid symbol name`) assert.Nil(t, got) }) t.Run("leaser without cache", func(t *testing.T) { @@ -102,7 +102,7 @@ func TestNewSchemaWatcher(t *testing.T) { } got, err := NewSchemaWatcher(ctx, config) require.Error(t, err) - assert.EqualError(t, err, "leaser config should only be present when cache config also present") + require.EqualError(t, err, "leaser config should only be present when cache config also present") assert.Nil(t, got) }) t.Run("successfully create schema watcher with default polling period", func(t *testing.T) { @@ -208,7 +208,7 @@ func TestSchemaWatcher_FindExtensionByName(t *testing.T) { } got, err := schemaWatcher.FindExtensionByName("foo.bar.xt") require.NoError(t, err) - assert.Equal(t, "foo.bar.xt", string(got.TypeDescriptor().FullName())) + require.Equal(t, "foo.bar.xt", string(got.TypeDescriptor().FullName())) } func TestSchemaWatcher_FindExtensionByNumber(t *testing.T) { @@ -220,7 +220,7 @@ func TestSchemaWatcher_FindExtensionByNumber(t *testing.T) { } got, err := schemaWatcher.FindExtensionByNumber("foo.bar.Message", protowire.Number(123)) require.NoError(t, err) - assert.Equal(t, "foo.bar.xt", string(got.TypeDescriptor().FullName())) + require.Equal(t, "foo.bar.xt", string(got.TypeDescriptor().FullName())) } func TestSchemaWatcher_FindMessageByName(t *testing.T) { @@ -232,7 +232,7 @@ func TestSchemaWatcher_FindMessageByName(t *testing.T) { } got, err := schemaWatcher.FindMessageByName("foo.bar.Message") require.NoError(t, err) - assert.Equal(t, "foo.bar.Message", string(got.Descriptor().FullName())) + require.Equal(t, "foo.bar.Message", string(got.Descriptor().FullName())) } func TestSchemaWatcher_FindMessageByURL(t *testing.T) { @@ -244,7 +244,7 @@ func TestSchemaWatcher_FindMessageByURL(t *testing.T) { } got, err := schemaWatcher.FindMessageByURL("foo.bar.Message") require.NoError(t, err) - assert.Equal(t, "foo.bar.Message", string(got.Descriptor().FullName())) + require.Equal(t, "foo.bar.Message", string(got.Descriptor().FullName())) } func TestSchemaWatcher_getResolver(t *testing.T) { @@ -252,7 +252,7 @@ func TestSchemaWatcher_getResolver(t *testing.T) { want := &resolver{} schemaWatcher := &SchemaWatcher{resolver: want} assert.True(t, schemaWatcher.resolverMu.TryRLock()) - assert.Equal(t, want, schemaWatcher.getResolver()) + require.Equal(t, want, schemaWatcher.getResolver()) assert.True(t, schemaWatcher.resolverMu.TryRLock()) } @@ -281,20 +281,20 @@ func TestSchemaWatcher_updateResolver(t *testing.T) { require.NoError(t, schemaWatcher.updateResolver(context.Background())) got, err := schemaWatcher.resolver.FindMessageByName("foo.bar.Message") require.NoError(t, err) - assert.Equal(t, "foo.bar.Message", string(got.Descriptor().FullName())) + require.Equal(t, "foo.bar.Message", string(got.Descriptor().FullName())) }) t.Run("updateResolver fails", func(t *testing.T) { t.Parallel() schemaWatcher := &SchemaWatcher{ poller: NewSchemaPoller(&fakeFileDescriptorSetService{ getFileDescriptorSetFunc: func(context.Context, *connect.Request[reflectv1beta1.GetFileDescriptorSetRequest]) (*connect.Response[reflectv1beta1.GetFileDescriptorSetResponse], error) { - return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("foo")) + return nil, connect.NewError(connect.CodeInternal, errors.New("foo")) }, }, "", ""), } err := schemaWatcher.updateResolver(context.Background()) require.Error(t, err) - assert.EqualError(t, err, "failed to fetch schema: internal: foo") + require.EqualError(t, err, "failed to fetch schema: internal: foo") }) t.Run("updateResolver fails", func(t *testing.T) { t.Parallel() @@ -364,7 +364,7 @@ func TestSchemaWatcher_AwaitReady(t *testing.T) { defer cancel() err = watcher.AwaitReady(timeoutCtx) require.Error(t, err) - require.True(t, errors.Is(err, context.DeadlineExceeded)) + require.ErrorIs(t, err, context.DeadlineExceeded) ok, _ := watcher.LastResolved() require.False(t, ok) require.Nil(t, watcher.ResolvedSchema()) @@ -405,7 +405,7 @@ func TestSchemaWatcher_AwaitReady(t *testing.T) { // download should have failed at least once so this should be the RPC error require.Error(t, err) var connErr *connect.Error - require.True(t, errors.As(err, &connErr)) + require.ErrorAs(t, err, &connErr) require.Equal(t, connect.CodeUnavailable, connErr.Code()) ok, _ := watcher.LastResolved() require.False(t, ok) @@ -436,7 +436,7 @@ func TestSchemaWatcher_AwaitReady(t *testing.T) { watcher.Stop() err = watcher.AwaitReady(ctx) require.Error(t, err) - require.True(t, errors.Is(err, ErrSchemaWatcherStopped)) + require.ErrorIs(t, err, ErrSchemaWatcherStopped) }) } @@ -476,12 +476,12 @@ func TestSchemaWatcher_UsingCache(t *testing.T) { require.GreaterOrEqual(t, len(loads), 1) // racing w/ retry so could be >1 require.Equal(t, "foo/bar:main", loads[0].key) saves := cache.getSaveCalls() - require.Equal(t, 0, len(saves)) + require.Empty(t, saves) // schema watcher cannot become ready if service unavailable and cache has no entry _, err = watcher.FindMessageByName("foo.bar.Message") require.Error(t, err) - require.True(t, errors.Is(err, ErrSchemaWatcherNotReady)) + require.ErrorIs(t, err, ErrSchemaWatcherNotReady) ok, _ := watcher.LastResolved() require.False(t, ok) }) @@ -509,10 +509,10 @@ func TestSchemaWatcher_UsingCache(t *testing.T) { err = watcher.AwaitReady(readyCtx) require.NoError(t, err) loads := cache.getLoadCalls() - require.Equal(t, 1, len(loads)) + require.Len(t, loads, 1) require.Equal(t, "foo/bar:main", loads[0].key) saves := cache.getSaveCalls() - require.Equal(t, 1, len(saves)) // just one call to seed cache above + require.Len(t, saves, 1) // just one call to seed cache above _, err = watcher.FindMessageByName("foo.bar.Message") require.NoError(t, err) @@ -547,7 +547,7 @@ func TestSchemaWatcher_UsingCache(t *testing.T) { case <-saveHookChan: } saves := cache.getSaveCalls() - require.Equal(t, 1, len(saves)) + require.Len(t, saves, 1) readyCtx, cancel := context.WithTimeout(ctx, time.Second) defer cancel() @@ -626,7 +626,7 @@ func TestSchemaWatcher_UsingLeaser(t *testing.T) { // One cache load for each follower loads := cache.getLoadCalls() - require.Equal(t, 3, len(loads)) + require.Len(t, loads, 3) } func TestSchemaWatcher_callbacks(t *testing.T) {