From cdc67f317b9e739fca1f2755d88f41c02c13374c Mon Sep 17 00:00:00 2001 From: Aman Mangal Date: Tue, 14 Feb 2023 12:43:24 +0530 Subject: [PATCH] chore(linter): fix golangci config and some issues in tests --- .golangci.yml | 28 +--- algo/packed_test.go | 1 + chunker/json_parser_test.go | 5 +- chunker/rdf_parser_test.go | 2 +- codec/codec_test.go | 9 +- conn/node_test.go | 4 +- contrib/integration/testtxn/main_test.go | 6 +- dgraph/cmd/alpha/http_test.go | 6 +- dgraph/cmd/alpha/run_test.go | 33 ++-- dgraph/cmd/alpha/upsert_test.go | 8 +- dgraph/cmd/live/load-json/load_test.go | 2 +- dgraph/cmd/live/load-uids/load_test.go | 2 +- dgraph/cmd/zero/zero_test.go | 3 +- dgraph/main.go | 2 - dql/bench_test.go | 5 +- dql/parser_test.go | 3 +- ee/acl/acl_test.go | 5 +- go.mod | 2 +- graphql/admin/http.go | 8 - .../poorman_auth_with_acl/admin_auth_test.go | 4 +- graphql/e2e/auth/add_mutation_test.go | 1 + graphql/e2e/auth/auth_test.go | 1 + graphql/e2e/auth/delete_mutation_test.go | 17 ++ graphql/e2e/auth/update_mutation_test.go | 2 +- .../auth_closed_by_default_test.go | 10 +- graphql/e2e/common/mutation.go | 1 + graphql/e2e/common/query.go | 1 + graphql/e2e/custom_logic/custom_logic_test.go | 1 + .../e2e/multi_tenancy/multi_tenancy_test.go | 1 + graphql/e2e/schema/schema_test.go | 1 + graphql/e2e/subscription/subscription_test.go | 1 + graphql/resolve/auth_test.go | 1 + graphql/resolve/mutation_test.go | 4 +- graphql/schema/response_test.go | 13 +- graphql/schema/wrappers_test.go | 1 + posting/list.go | 3 +- posting/list_test.go | 72 +++++---- posting/lmap_test.go | 2 +- query/common_test.go | 26 +-- query/fastjson_test.go | 21 ++- query/outputnode_test.go | 22 +-- query/query0_test.go | 1 + query/query1_test.go | 1 + query/query2_test.go | 1 + query/query3_test.go | 1 + query/query_facets_test.go | 149 +++++++++--------- raftwal/storage_test.go | 10 +- systest/acl/restore/acl_restore_test.go | 2 +- systest/audit/audit_test.go | 2 +- systest/backup/encryption/backup_test.go | 2 +- systest/backup/minio/backup_test.go | 2 +- systest/bgindex/count_test.go | 11 +- systest/bgindex/parallel_test.go | 6 +- systest/bgindex/string_test.go | 6 +- systest/bulk_live/common/bulk_live_cases.go | 6 +- systest/export/export_test.go | 2 +- systest/license/license_test.go | 2 +- systest/live_pw_test.go | 2 +- systest/mutations_test.go | 31 ++-- systest/queries_test.go | 1 + t/t.go | 6 +- testutil/graphql.go | 1 + tok/tok.go | 3 +- types/s2index_test.go | 4 +- types/scalar_types_test.go | 6 +- upgrade/change_v21.03.0.go | 2 +- worker/export_test.go | 6 +- worker/snapshot_test.go | 3 +- x/error_test.go | 6 +- x/x.go | 6 +- 70 files changed, 328 insertions(+), 293 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 89a41eac049..623c9e7db4c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,20 +1,15 @@ run: - tests: false skip-dirs: - - contrib - - compose - - graphql/bench - - graphql/e2e - - graphql/test - - graphql/testdata - - systest - - t skip-files: - - ".*test.go$" linters-settings: lll: line-length: 120 + staticcheck: + checks: + - all + - '-SA1019' # it is okay to use math/rand at times. + # we should review this again when we upgrade to go 1.20 linters: disable-all: true @@ -26,15 +21,6 @@ linters: - gosimple - govet - lll - - varcheck - unused - -issues: - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - - linters: - - golint - text: "(const|var|type|method|func|struct field) .+ should be" - - linters: - - golint - text: "(method parameter|func parameter|func result) .+ should be" + - staticcheck + - goimports diff --git a/algo/packed_test.go b/algo/packed_test.go index b3e33f81486..03c9f54dfa0 100644 --- a/algo/packed_test.go +++ b/algo/packed_test.go @@ -42,6 +42,7 @@ func TestMergeSorted1Packed(t *testing.T) { require.Equal(t, []uint64{55}, codec.Decode(MergeSortedPacked(input), 0)) } +//nolint:unused func printPack(t *testing.T, pack *pb.UidPack) { for _, block := range pack.Blocks { t.Logf("[%x]Block base: %d. Num uids: %d. Deltas: %x\n", diff --git a/chunker/json_parser_test.go b/chunker/json_parser_test.go index 3ad2eb0262d..0906734de05 100644 --- a/chunker/json_parser_test.go +++ b/chunker/json_parser_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package chunker import ( @@ -1229,7 +1230,7 @@ func BenchmarkNoFacets(b *testing.B) { // we're parsing 125 nquads at a time, so the MB/s == MNquads/s b.SetBytes(125) for n := 0; n < b.N; n++ { - Parse([]byte(json), SetNquads) + _, _ = Parse([]byte(json), SetNquads) } } @@ -1370,6 +1371,6 @@ func BenchmarkNoFacetsFast(b *testing.B) { // we're parsing 125 nquads at a time, so the MB/s == MNquads/s b.SetBytes(125) for n := 0; n < b.N; n++ { - FastParse([]byte(json), SetNquads) + _, _ = FastParse([]byte(json), SetNquads) } } diff --git a/chunker/rdf_parser_test.go b/chunker/rdf_parser_test.go index 2978bdffdf1..22eb351c5f0 100644 --- a/chunker/rdf_parser_test.go +++ b/chunker/rdf_parser_test.go @@ -760,7 +760,7 @@ var testNQuads = []struct { }, // Should parse dates { - input: `_:alice "stuff" (key1=2002-10-02T15:00:00.05Z, key2=2006-01-02T15:04:05, key3=2006-01-02T00:00:00Z) .`, + input: `_:alice "stuff" (key1=2002-10-02T15:00:00.05Z, key2=2006-01-02T15:04:05, key3=2006-01-02T00:00:00Z) .`, //nolint:lll nq: api.NQuad{ Subject: "_:alice", Predicate: "knows", diff --git a/codec/codec_test.go b/codec/codec_test.go index ca0c6b7747b..ed131756729 100644 --- a/codec/codec_test.go +++ b/codec/codec_test.go @@ -78,7 +78,10 @@ func TestBufferUidPack(t *testing.T) { FreePack(pack) buf := z.NewBuffer(10<<10, "TestBufferUidPack") - defer buf.Release() + defer func() { + require.NoError(t, buf.Release()) + }() + DecodeToBuffer(buf, &pb.UidPack{}) require.Equal(t, 0, buf.LenNoPadding()) require.NoError(t, buf.Release()) @@ -96,7 +99,9 @@ func TestBufferUidPack(t *testing.T) { require.Equal(t, expected, actual) actualbuffer := z.NewBuffer(10<<10, "TestBufferUidPack") - defer actualbuffer.Release() + defer func() { + require.NoError(t, actualbuffer.Release()) + }() DecodeToBuffer(actualbuffer, pack) enc := EncodeFromBuffer(actualbuffer.Bytes(), 256) diff --git a/conn/node_test.go b/conn/node_test.go index 815541ffa0a..5d49a1ed2b1 100644 --- a/conn/node_test.go +++ b/conn/node_test.go @@ -46,7 +46,9 @@ func (n *Node) run(wg *sync.WaitGroup) { for _, entry := range rd.CommittedEntries { if entry.Type == raftpb.EntryConfChange { var cc raftpb.ConfChange - cc.Unmarshal(entry.Data) + if err := cc.Unmarshal(entry.Data); err != nil { + fmt.Printf("error in unmarshalling: %v\n", err) + } n.Raft().ApplyConfChange(cc) } else if entry.Type == raftpb.EntryNormal { if bytes.HasPrefix(entry.Data, []byte("hey")) { diff --git a/contrib/integration/testtxn/main_test.go b/contrib/integration/testtxn/main_test.go index d90052e24a8..7164542d0ab 100644 --- a/contrib/integration/testtxn/main_test.go +++ b/contrib/integration/testtxn/main_test.go @@ -46,7 +46,7 @@ var s state func TestMain(m *testing.M) { log.SetFlags(log.LstdFlags | log.Lshortfile) - testutil.AssignUids(200) + x.CheckfNoTrace(testutil.AssignUids(200)) dg, err := testutil.DgraphClientWithGroot(testutil.SockAddr) x.CheckfNoTrace(err) s.dg = dg @@ -442,7 +442,7 @@ func TestReadIndexKeySameTxn(t *testing.T) { } txn = s.dg.NewTxn() - defer txn.Discard(context.Background()) + defer func() { require.NoError(t, txn.Discard(context.Background())) }() q := `{ me(func: le(name, "Manish")) { uid }}` resp, err := txn.Query(context.Background(), q) if err != nil { @@ -883,7 +883,7 @@ func TestConcurrentQueryMutate(t *testing.T) { alterSchema(s.dg, "name: string .") txn := s.dg.NewTxn() - defer txn.Discard(context.Background()) + defer func() { require.NoError(t, txn.Discard(context.Background())) }() // Do one query, so a new timestamp is assigned to the txn. q := `{me(func: uid(0x01)) { name }}` diff --git a/dgraph/cmd/alpha/http_test.go b/dgraph/cmd/alpha/http_test.go index a6b28a97aac..be55e724f3a 100644 --- a/dgraph/cmd/alpha/http_test.go +++ b/dgraph/cmd/alpha/http_test.go @@ -108,8 +108,8 @@ func queryWithGz(queryText, contentType, debug, timeout string, gzReq, gzResp bo if gzReq { var b bytes.Buffer gz := gzip.NewWriter(&b) - gz.Write([]byte(queryText)) - gz.Close() + _, _ = gz.Write([]byte(queryText)) + _ = gz.Close() buf = &b } else { buf = bytes.NewBufferString(queryText) @@ -311,7 +311,7 @@ func runRequest(req *http.Request) (*x.QueryResWithData, []byte, *http.Response, } qr := new(x.QueryResWithData) - json.Unmarshal(body, qr) // Don't check error. + _ = json.Unmarshal(body, qr) // Don't check error. if len(qr.Errors) > 0 { return nil, nil, resp, errors.New(qr.Errors[0].Message) } diff --git a/dgraph/cmd/alpha/run_test.go b/dgraph/cmd/alpha/run_test.go index a54a6de25a2..9976a3c9252 100644 --- a/dgraph/cmd/alpha/run_test.go +++ b/dgraph/cmd/alpha/run_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package alpha import ( @@ -216,7 +217,7 @@ func TestDeletePredicate(t *testing.T) { friend: string @index(term) . ` require.NoError(t, dropAll()) - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := alterSchemaWithRetry(s1) require.NoError(t, err) @@ -446,7 +447,7 @@ func TestSchemaMutationIndexAdd(t *testing.T) { ` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := runMutation(m) require.NoError(t, err) @@ -486,7 +487,7 @@ func TestSchemaMutationIndexRemove(t *testing.T) { ` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) // add index to name err := alterSchemaWithRetry(s1) require.NoError(t, err) @@ -530,7 +531,7 @@ func TestSchemaMutationReverseAdd(t *testing.T) { var s = `friend: [uid] @reverse .` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := runMutation(m) require.NoError(t, err) @@ -574,7 +575,7 @@ func TestSchemaMutationReverseRemove(t *testing.T) { ` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := runMutation(m) require.NoError(t, err) @@ -621,7 +622,7 @@ func TestSchemaMutationCountAdd(t *testing.T) { ` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := runMutation(m) require.NoError(t, err) @@ -677,7 +678,7 @@ func TestJsonMutation(t *testing.T) { name: string @index(exact) . ` require.NoError(t, dropAll()) - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := alterSchemaWithRetry(s1) require.NoError(t, err) @@ -732,7 +733,7 @@ func TestJsonMutationNumberParsing(t *testing.T) { } ` require.NoError(t, dropAll()) - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := runJSONMutation(m1) require.NoError(t, err) @@ -818,7 +819,7 @@ func TestDeleteAll(t *testing.T) { friend: [uid] @reverse . name: string @index(term) . ` - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := alterSchemaWithRetry(s1) require.NoError(t, err) @@ -926,7 +927,7 @@ func TestSchemaMutation4Error(t *testing.T) { age:int . ` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := alterSchemaWithRetry(m) require.NoError(t, err) @@ -957,7 +958,7 @@ func TestSchemaMutation5Error(t *testing.T) { friends: [uid] . ` // reset Schema - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := alterSchemaWithRetry(m) require.NoError(t, err) @@ -980,7 +981,7 @@ func TestSchemaMutation5Error(t *testing.T) { // A basic sanity check. We will do more extensive testing for multiple values in query. func TestMultipleValues(t *testing.T) { - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) m := ` occupations: [string] . ` @@ -1011,7 +1012,7 @@ func TestMultipleValues(t *testing.T) { func TestListTypeSchemaChange(t *testing.T) { require.NoError(t, dropAll()) - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) m := ` occupations: [string] @index(term) . ` @@ -1106,7 +1107,7 @@ func TestDeleteAllSP2(t *testing.T) { } ` require.NoError(t, dropAll()) - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) err := alterSchemaWithRetry(s) require.NoError(t, err) @@ -1385,7 +1386,7 @@ func TestGrpcCompressionSupport(t *testing.T) { require.NoError(t, err) dc := dgo.NewDgraphClient(api.NewDgraphClient(conn)) - dc.LoginIntoNamespace(context.Background(), x.GrootId, "password", x.GalaxyNamespace) + require.NoError(t, dc.LoginIntoNamespace(context.Background(), x.GrootId, "password", x.GalaxyNamespace)) q := `schema {}` tx := dc.NewTxn() _, err = tx.Query(context.Background(), q) @@ -1503,7 +1504,7 @@ func TestIPStringParsing(t *testing.T) { } func TestJSONQueryWithVariables(t *testing.T) { - schema.ParseBytes([]byte(""), 1) + require.NoError(t, schema.ParseBytes([]byte(""), 1)) m := ` user_id: string @index(exact) @upsert . user_name: string @index(hash) . diff --git a/dgraph/cmd/alpha/upsert_test.go b/dgraph/cmd/alpha/upsert_test.go index 052cf62d739..70cdd0ecef4 100644 --- a/dgraph/cmd/alpha/upsert_test.go +++ b/dgraph/cmd/alpha/upsert_test.go @@ -2774,7 +2774,7 @@ func TestUpsertMultiValueJson(t *testing.T) { // delete color for employess of company1 and set color for employees of company2 m3 := ` { - "query": "{user1(func: eq(works_for, \"company1\")) {c1 as uid} user2(func: eq(works_for, \"company2\")) {c2 as uid}}", + "query": "{u1(func: eq(works_for, \"company1\")) {c1 as uid} u2(func: eq(works_for, \"company2\")) {c2 as uid}}", "mutations": [ { "delete": [ @@ -2800,8 +2800,8 @@ func TestUpsertMultiValueJson(t *testing.T) { require.NoError(t, err) result = QueryResult{} require.NoError(t, json.Unmarshal(mr.data, &result)) - require.Equal(t, 2, len(result.Queries["user1"])) - require.Equal(t, 2, len(result.Queries["user2"])) + require.Equal(t, 2, len(result.Queries["u1"])) + require.Equal(t, 2, len(result.Queries["u2"])) } func TestValVarWithBlankNode(t *testing.T) { @@ -2866,7 +2866,7 @@ upsert { // This test may fail sometimes because ACL token // can get expired while the mutations is running. -func upsertTooBigTest(t *testing.T) { +func upsertTooBigTest(t *testing.T) { //nolint:unused require.NoError(t, dropAll()) for i := 0; i < 1e6+1; { diff --git a/dgraph/cmd/live/load-json/load_test.go b/dgraph/cmd/live/load-json/load_test.go index a880342b7d9..a4e99e67a91 100644 --- a/dgraph/cmd/live/load-json/load_test.go +++ b/dgraph/cmd/live/load-json/load_test.go @@ -190,7 +190,7 @@ func TestMain(m *testing.M) { // instead of all over /tmp or the working directory. tmpDir, err := os.MkdirTemp("", "test.tmp-") x.Check(err) - os.Chdir(tmpDir) + x.Check(os.Chdir(tmpDir)) defer os.RemoveAll(tmpDir) os.Exit(m.Run()) diff --git a/dgraph/cmd/live/load-uids/load_test.go b/dgraph/cmd/live/load-uids/load_test.go index ab35d0fc0d5..fed9f9fa139 100644 --- a/dgraph/cmd/live/load-uids/load_test.go +++ b/dgraph/cmd/live/load-uids/load_test.go @@ -399,7 +399,7 @@ func TestMain(m *testing.M) { // instead of all over /tmp or the working directory. tmpDir, err := os.MkdirTemp("", "test.tmp-") x.Check(err) - os.Chdir(tmpDir) + x.Check(os.Chdir(tmpDir)) defer os.RemoveAll(tmpDir) os.Exit(m.Run()) diff --git a/dgraph/cmd/zero/zero_test.go b/dgraph/cmd/zero/zero_test.go index cfec82269ce..03d21d129dc 100644 --- a/dgraph/cmd/zero/zero_test.go +++ b/dgraph/cmd/zero/zero_test.go @@ -89,10 +89,9 @@ func TestIdBump(t *testing.T) { } func TestProposalKey(t *testing.T) { - id := uint64(2) node := &node{Node: &conn.Node{Id: id}, ctx: context.Background(), closer: z.NewCloser(1)} - node.initProposalKey(node.Id) + require.NoError(t, node.initProposalKey(node.Id)) pkey := proposalKey nodeIdFromKey := proposalKey >> 48 diff --git a/dgraph/main.go b/dgraph/main.go index 6a468725a6e..aff55a619ce 100644 --- a/dgraph/main.go +++ b/dgraph/main.go @@ -65,8 +65,6 @@ func main() { humanize.IBytes(js.Active), humanize.IBytes(js.Allocated), humanize.IBytes(js.Resident), humanize.IBytes(js.Retained)) lastAlloc = uint64(z.NumAllocBytes()) - } else { - // Don't update the lastJs here. } runtime.ReadMemStats(&ms) diff --git a/dql/bench_test.go b/dql/bench_test.go index d2d2cf788c5..20b71e50234 100644 --- a/dql/bench_test.go +++ b/dql/bench_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package dql import ( @@ -28,7 +29,7 @@ var sc = `type.object.name.en: string @index . film.film.initial_release_date: date @index .` func benchmarkParsingHelper(b *testing.B, q string) { - schema.ParseBytes([]byte(sc), 1) + _ = schema.ParseBytes([]byte(sc), 1) b.ResetTimer() for i := 0; i < b.N; i++ { _, err := Parse(Request{Str: q}) @@ -37,7 +38,7 @@ func benchmarkParsingHelper(b *testing.B, q string) { } func benchmarkParsingParallelHelper(b *testing.B, q string) { - schema.ParseBytes([]byte(sc), 1) + _ = schema.ParseBytes([]byte(sc), 1) b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { diff --git a/dql/parser_test.go b/dql/parser_test.go index 8ea34efafdd..3518c93989a 100644 --- a/dql/parser_test.go +++ b/dql/parser_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package dql import ( @@ -4246,7 +4247,7 @@ func TestParserFuzz(t *testing.T) { } }() - Parse(Request{Str: test.in}) + _, _ = Parse(Request{Str: test.in}) }) } } diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index 8a087ca2ee7..d5d30c7a112 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -994,8 +994,7 @@ func TestGuardianAccess(t *testing.T) { time.Sleep(defaultTimeToSleep) gClient, err := testutil.DgraphClient(testutil.SockAddr) require.NoError(t, err, "Error while creating client") - - gClient.LoginIntoNamespace(ctx, "guardian", "guardianpass", x.GalaxyNamespace) + require.NoError(t, gClient.LoginIntoNamespace(ctx, "guardian", "guardianpass", x.GalaxyNamespace)) mutString := fmt.Sprintf("<%s> \"testdata\" .", nodeUID) mutation = &api.Mutation{SetNquads: []byte(mutString), CommitNow: true} @@ -1593,7 +1592,7 @@ func TestValQueryWithACLPermissions(t *testing.T) { "alice has access to name and age", `{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}], - "q2":[{"name":"RandomGuy2","val(n)":"RandomGuy2","val(a)":25},{"name":"RandomGuy","val(n)":"RandomGuy","val(a)":23}]}`, + "q2":[{"name":"RandomGuy2","val(n)":"RandomGuy2","val(a)":25},{"name":"RandomGuy","val(n)":"RandomGuy","val(a)":23}]}`, //nolint:lll }, { `{ diff --git a/go.mod b/go.mod index 69e294be309..022f246855a 100644 --- a/go.mod +++ b/go.mod @@ -57,6 +57,7 @@ require ( golang.org/x/net v0.5.0 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 golang.org/x/sys v0.4.0 + golang.org/x/term v0.4.0 golang.org/x/text v0.6.0 golang.org/x/tools v0.1.12 google.golang.org/grpc v1.52.0 @@ -128,7 +129,6 @@ require ( go.uber.org/atomic v1.6.0 // indirect go.uber.org/multierr v1.5.0 // indirect golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/term v0.4.0 // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/api v0.30.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/graphql/admin/http.go b/graphql/admin/http.go index 57ce69b112a..0715a9148b4 100644 --- a/graphql/admin/http.go +++ b/graphql/admin/http.go @@ -135,10 +135,6 @@ type graphqlSubscription struct { } func (gs *graphqlSubscription) isValid(namespace uint64) error { - if gs == nil { - return errors.New("gs is nil") - } - gs.graphqlHandler.pollerMux.RLock() defer gs.graphqlHandler.pollerMux.RUnlock() if err := gs.graphqlHandler.isValid(namespace); err != nil { @@ -281,10 +277,6 @@ func (gh *graphqlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (gh *graphqlHandler) isValid(namespace uint64) error { - if gh == nil { - return errors.New("gh is nil") - } - gh.resolverMux.RLock() defer gh.resolverMux.RUnlock() switch { diff --git a/graphql/e2e/admin_auth/poorman_auth_with_acl/admin_auth_test.go b/graphql/e2e/admin_auth/poorman_auth_with_acl/admin_auth_test.go index fb8a0efc2c6..745c8e23fc0 100644 --- a/graphql/e2e/admin_auth/poorman_auth_with_acl/admin_auth_test.go +++ b/graphql/e2e/admin_auth/poorman_auth_with_acl/admin_auth_test.go @@ -95,7 +95,7 @@ func assertAuthTokenError(t *testing.T, resp *common.GraphQLResponse) { func assertMissingAclError(t *testing.T, resp *common.GraphQLResponse) { require.Equal(t, x.GqlErrorList{{ - Message: "resolving updateGQLSchema failed because rpc error: code = PermissionDenied desc = no accessJwt available", + Message: "resolving updateGQLSchema failed because rpc error: code = PermissionDenied desc = no accessJwt available", //nolint:lll Locations: []x.Location{{ Line: 2, Column: 4, @@ -105,7 +105,7 @@ func assertMissingAclError(t *testing.T, resp *common.GraphQLResponse) { func assertBadAclError(t *testing.T, resp *common.GraphQLResponse) { require.Equal(t, x.GqlErrorList{{ - Message: "resolving updateGQLSchema failed because rpc error: code = Unauthenticated desc = unable to parse jwt token: token contains an invalid number of segments", + Message: "resolving updateGQLSchema failed because rpc error: code = Unauthenticated desc = unable to parse jwt token: token contains an invalid number of segments", //nolint:lll Locations: []x.Location{{ Line: 2, Column: 4, diff --git a/graphql/e2e/auth/add_mutation_test.go b/graphql/e2e/auth/add_mutation_test.go index e8f1b4523ea..d8d90e65608 100644 --- a/graphql/e2e/auth/add_mutation_test.go +++ b/graphql/e2e/auth/add_mutation_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package auth import ( diff --git a/graphql/e2e/auth/auth_test.go b/graphql/e2e/auth/auth_test.go index 689d060ebef..5eb34249cd6 100644 --- a/graphql/e2e/auth/auth_test.go +++ b/graphql/e2e/auth/auth_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package auth import ( diff --git a/graphql/e2e/auth/delete_mutation_test.go b/graphql/e2e/auth/delete_mutation_test.go index 6fcb5d2011c..1ff8ce4a2b2 100644 --- a/graphql/e2e/auth/delete_mutation_test.go +++ b/graphql/e2e/auth/delete_mutation_test.go @@ -1,3 +1,20 @@ +/* + * Copyright 2023 Dgraph Labs, Inc. and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//nolint:lll package auth import ( diff --git a/graphql/e2e/auth/update_mutation_test.go b/graphql/e2e/auth/update_mutation_test.go index d35b151492c..b492b1fb769 100644 --- a/graphql/e2e/auth/update_mutation_test.go +++ b/graphql/e2e/auth/update_mutation_test.go @@ -744,7 +744,7 @@ func TestUpdateNestedFilter(t *testing.T) { }, { user: "user2", role: "USER", - result: `{"updateMovie": {"movie": [{ "content": "Movie1" }, { "content": "Movie2" }, { "content": "Movie3" }, { "content": "Movie4" }]}}`, + result: `{"updateMovie": {"movie": [{ "content": "Movie1" }, { "content": "Movie2" }, { "content": "Movie3" }, { "content": "Movie4" }]}}`, //nolint:lll }} query := ` diff --git a/graphql/e2e/auth_closed_by_default/auth_closed_by_default_test.go b/graphql/e2e/auth_closed_by_default/auth_closed_by_default_test.go index 2b226de7659..0c2a01da41b 100644 --- a/graphql/e2e/auth_closed_by_default/auth_closed_by_default_test.go +++ b/graphql/e2e/auth_closed_by_default/auth_closed_by_default_test.go @@ -203,13 +203,5 @@ func TestMain(m *testing.M) { panic(err) } common.BootstrapServer(authSchema, data) - // Data is added only in the first iteration, but the schema is added every iteration. - if data != nil { - data = nil - } - exitCode := m.Run() - if exitCode != 0 { - os.Exit(exitCode) - } - os.Exit(0) + os.Exit(m.Run()) } diff --git a/graphql/e2e/common/mutation.go b/graphql/e2e/common/mutation.go index 4cda009d398..b20c206d353 100644 --- a/graphql/e2e/common/mutation.go +++ b/graphql/e2e/common/mutation.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package common // Tests that mutate the GraphQL database should return the database state to what it diff --git a/graphql/e2e/common/query.go b/graphql/e2e/common/query.go index 1e83e049619..aa74dad0038 100644 --- a/graphql/e2e/common/query.go +++ b/graphql/e2e/common/query.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package common import ( diff --git a/graphql/e2e/custom_logic/custom_logic_test.go b/graphql/e2e/custom_logic/custom_logic_test.go index d1295bca9f7..5807ccd6698 100644 --- a/graphql/e2e/custom_logic/custom_logic_test.go +++ b/graphql/e2e/custom_logic/custom_logic_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package custom_logic import ( diff --git a/graphql/e2e/multi_tenancy/multi_tenancy_test.go b/graphql/e2e/multi_tenancy/multi_tenancy_test.go index 5b8f611ad6e..07be6bbe324 100644 --- a/graphql/e2e/multi_tenancy/multi_tenancy_test.go +++ b/graphql/e2e/multi_tenancy/multi_tenancy_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package multi_tenancy import ( diff --git a/graphql/e2e/schema/schema_test.go b/graphql/e2e/schema/schema_test.go index 42dc0911f52..43adef065cd 100644 --- a/graphql/e2e/schema/schema_test.go +++ b/graphql/e2e/schema/schema_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package schema import ( diff --git a/graphql/e2e/subscription/subscription_test.go b/graphql/e2e/subscription/subscription_test.go index 3ecf4c277e6..c1c800ff5fa 100644 --- a/graphql/e2e/subscription/subscription_test.go +++ b/graphql/e2e/subscription/subscription_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package subscription_test import ( diff --git a/graphql/resolve/auth_test.go b/graphql/resolve/auth_test.go index 6867c5ae8e6..050fd051893 100644 --- a/graphql/resolve/auth_test.go +++ b/graphql/resolve/auth_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package resolve import ( diff --git a/graphql/resolve/mutation_test.go b/graphql/resolve/mutation_test.go index d734086667f..198397da50b 100644 --- a/graphql/resolve/mutation_test.go +++ b/graphql/resolve/mutation_test.go @@ -151,8 +151,8 @@ func benchmark3LevelDeep(num int, b *testing.B) { addRewriter := NewAddRewriter() idExistence := make(map[string]string) for n := 0; n < b.N; n++ { - addRewriter.RewriteQueries(context.Background(), mut) - addRewriter.Rewrite(context.Background(), mut, idExistence) + _, _, _ = addRewriter.RewriteQueries(context.Background(), mut) + _, _ = addRewriter.Rewrite(context.Background(), mut, idExistence) } } diff --git a/graphql/schema/response_test.go b/graphql/schema/response_test.go index 3d4a4621c8d..12b8fae219b 100644 --- a/graphql/schema/response_test.go +++ b/graphql/schema/response_test.go @@ -22,6 +22,7 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/dgraph-io/dgraph/x" "github.com/dgraph-io/gqlparser/v2/gqlerror" @@ -115,7 +116,8 @@ func TestDataAndErrors(t *testing.T) { } buf := new(bytes.Buffer) - resp.WriteTo(buf) + _, err := resp.WriteTo(buf) + require.NoError(t, err) assert.JSONEq(t, tcase.expected, buf.String()) }) @@ -127,7 +129,8 @@ func TestWriteTo_BadData(t *testing.T) { resp.AddData([]byte(`not json`)) buf := new(bytes.Buffer) - resp.WriteTo(buf) + _, err := resp.WriteTo(buf) + require.NoError(t, err) assert.JSONEq(t, `{"errors":[{"message":"Internal error - failed to marshal a valid JSON response"}], @@ -185,7 +188,8 @@ func TestErrorResponse(t *testing.T) { resp := ErrorResponse(tcase.err) buf := new(bytes.Buffer) - resp.WriteTo(buf) + _, err := resp.WriteTo(buf) + require.NoError(t, err) assert.JSONEq(t, tcase.expected, buf.String()) }) @@ -196,7 +200,8 @@ func TestNilResponse(t *testing.T) { var resp *Response buf := new(bytes.Buffer) - resp.WriteTo(buf) + _, err := resp.WriteTo(buf) + require.NoError(t, err) assert.JSONEq(t, `{"errors":[{"message":"Internal error - no response to write."}], diff --git a/graphql/schema/wrappers_test.go b/graphql/schema/wrappers_test.go index 618b9ed2ee4..9c9475d6116 100644 --- a/graphql/schema/wrappers_test.go +++ b/graphql/schema/wrappers_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package schema import ( diff --git a/posting/list.go b/posting/list.go index a3c932b7f89..2468821eb2f 100644 --- a/posting/list.go +++ b/posting/list.go @@ -957,7 +957,8 @@ func sanityCheck(prefix string, out *rollupOutput) { paddr := fmt.Sprintf("%p", pack) baddr := fmt.Sprintf("%p", block) if pa, has := seen[baddr]; has { - glog.Fatalf("[%s %s] Have already seen this block: %s in pa:%s. Now found in pa: %s (num blocks: %d) as well. Block [base: %d. Len: %d] Full map size: %d. \n", + glog.Fatalf("[%s %s] Have already seen this block: %s in pa:%s. "+ + "Now found in pa: %s (num blocks: %d) as well. Block [base: %d. Len: %d] Full map size: %d", prefix, which, baddr, pa, paddr, len(pack.Blocks), block.Base, len(block.Deltas), len(seen)) } seen[baddr] = which + "_" + paddr diff --git a/posting/list_test.go b/posting/list_test.go index ef4cbffda4f..3c3172f3207 100644 --- a/posting/list_test.go +++ b/posting/list_test.go @@ -50,10 +50,10 @@ func (l *List) PostingList() *pb.PostingList { func listToArray(t *testing.T, afterUid uint64, l *List, readTs uint64) []uint64 { out := make([]uint64, 0, 10) - l.Iterate(readTs, afterUid, func(p *pb.Posting) error { + require.NoError(t, l.Iterate(readTs, afterUid, func(p *pb.Posting) error { out = append(out, p.Uid) return nil - }) + })) return out } @@ -124,7 +124,7 @@ func TestAddMutation(t *testing.T) { require.Equal(t, listToArray(t, 0, l, 1), []uint64{9}) - p := getFirst(l, 1) + p := getFirst(t, l, 1) require.NotNil(t, p, "Unable to retrieve posting") require.EqualValues(t, "testing", p.Facets[0].Key) @@ -150,26 +150,26 @@ func TestAddMutation(t *testing.T) { edge.ValueId = 9 edge.Facets = []*api.Facet{{Key: "anti-testing"}} addMutationHelper(t, l, edge, Set, txn) - l.commitMutation(1, 2) + require.NoError(t, l.commitMutation(1, 2)) uids := []uint64{9, 69, 81} checkUids(t, l, uids, 3) - p = getFirst(l, 3) + p = getFirst(t, l, 3) require.NotNil(t, p, "Unable to retrieve posting") require.EqualValues(t, "anti-testing", p.Facets[0].Key) } -func getFirst(l *List, readTs uint64) (res pb.Posting) { - l.Iterate(readTs, 0, func(p *pb.Posting) error { +func getFirst(t *testing.T, l *List, readTs uint64) (res pb.Posting) { + require.NoError(t, l.Iterate(readTs, 0, func(p *pb.Posting) error { res = *p return ErrStopIteration - }) + })) return res } func checkValue(t *testing.T, ol *List, val string, readTs uint64) { - p := getFirst(ol, readTs) + p := getFirst(t, ol, readTs) require.Equal(t, uint64(math.MaxUint64), p.Uid) // Cast to prevent overflow. require.EqualValues(t, val, p.Value) } @@ -187,7 +187,7 @@ func TestAddMutation_Value(t *testing.T) { checkValue(t, ol, "oh hey there", txn.StartTs) // Run the same check after committing. - ol.commitMutation(txn.StartTs, txn.StartTs+1) + require.NoError(t, ol.commitMutation(txn.StartTs, txn.StartTs+1)) checkValue(t, ol, "oh hey there", uint64(3)) // The value made it to the posting list. Changing it now. @@ -208,7 +208,7 @@ func TestAddMutation_jchiu1(t *testing.T) { } txn := &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) // TODO: Read at commitTimestamp with all committed require.EqualValues(t, 1, ol.Length(uint64(3), 0)) @@ -261,7 +261,7 @@ func TestAddMutation_DelSet(t *testing.T) { } txn = &Txn{StartTs: 2} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(2, uint64(3)) + require.NoError(t, ol.commitMutation(2, uint64(3))) require.EqualValues(t, 1, ol.Length(3, 0)) checkValue(t, ol, "newcars", 3) } @@ -277,7 +277,7 @@ func TestAddMutation_DelRead(t *testing.T) { } txn := &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) require.EqualValues(t, 1, ol.Length(2, 0)) checkValue(t, ol, "newcars", 2) @@ -296,7 +296,7 @@ func TestAddMutation_DelRead(t *testing.T) { require.EqualValues(t, 0, ol.Length(3, 0)) // Commit sp* only in oracle, don't apply to pl yet - ol.commitMutation(3, 5) + require.NoError(t, ol.commitMutation(3, 5)) // This read should ignore sp*, since readts is 4 and it was committed at 5 require.EqualValues(t, 1, ol.Length(4, 0)) @@ -338,7 +338,7 @@ func TestAddMutation_jchiu2_Commit(t *testing.T) { } txn := &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Del, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) require.EqualValues(t, 0, ol.Length(uint64(3), 0)) // Set value to newcars, but don't merge yet. @@ -347,7 +347,7 @@ func TestAddMutation_jchiu2_Commit(t *testing.T) { } txn = &Txn{StartTs: 3} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(3, uint64(4)) + require.NoError(t, ol.commitMutation(3, uint64(4))) require.EqualValues(t, 1, ol.Length(5, 0)) checkValue(t, ol, "newcars", 5) } @@ -363,7 +363,7 @@ func TestAddMutation_jchiu3(t *testing.T) { } txn := &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) require.Equal(t, 1, ol.Length(uint64(3), 0)) require.EqualValues(t, 1, ol.Length(uint64(3), 0)) checkValue(t, ol, "cars", uint64(3)) @@ -403,7 +403,7 @@ func TestAddMutation_mrjn1(t *testing.T) { } txn := &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) // Delete the previously committed value cars. But don't merge. txn = &Txn{StartTs: 3} @@ -573,7 +573,7 @@ func TestAddMutation_gru(t *testing.T) { ValueId: 0x29bf442b48a772e0, } addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) } { @@ -586,7 +586,7 @@ func TestAddMutation_gru(t *testing.T) { ValueId: 0x2b693088816b04b7, } addMutationHelper(t, ol, edge, Del, txn) - ol.commitMutation(3, uint64(4)) + require.NoError(t, ol.commitMutation(3, uint64(4))) } } @@ -607,7 +607,7 @@ func TestAddMutation_gru2(t *testing.T) { } txn = &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) } { @@ -627,7 +627,7 @@ func TestAddMutation_gru2(t *testing.T) { } addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(3, uint64(4)) + require.NoError(t, ol.commitMutation(3, uint64(4))) } // Posting list should just have the new tag. @@ -648,7 +648,7 @@ func TestAddAndDelMutation(t *testing.T) { } txn := &Txn{StartTs: 1} addMutationHelper(t, ol, edge, Set, txn) - ol.commitMutation(1, uint64(2)) + require.NoError(t, ol.commitMutation(1, uint64(2))) } { @@ -658,7 +658,7 @@ func TestAddAndDelMutation(t *testing.T) { txn := &Txn{StartTs: 3} addMutationHelper(t, ol, edge, Del, txn) addMutationHelper(t, ol, edge, Del, txn) - ol.commitMutation(3, uint64(4)) + require.NoError(t, ol.commitMutation(3, uint64(4))) checkUids(t, ol, []uint64{}, 5) } @@ -780,7 +780,7 @@ func TestDelete(t *testing.T) { edge.Value = []byte(x.Star) addMutationHelper(t, ol, edge, Del, txn) require.EqualValues(t, 0, ol.Length(txn.StartTs, 0)) - ol.commitMutation(txn.StartTs, txn.StartTs+1) + require.NoError(t, ol.commitMutation(txn.StartTs, txn.StartTs+1)) require.EqualValues(t, 0, ol.Length(txn.StartTs+2, 0)) } @@ -803,7 +803,7 @@ func TestAfterUIDCountWithCommit(t *testing.T) { require.EqualValues(t, 0, ol.Length(txn.StartTs, 400)) // Commit to database. - ol.commitMutation(txn.StartTs, txn.StartTs+1) + require.NoError(t, ol.commitMutation(txn.StartTs, txn.StartTs+1)) txn = &Txn{StartTs: 3} // Mutation layer starts afresh from here. @@ -977,7 +977,7 @@ func TestLargePlistSplit(t *testing.T) { ol, err := getNew(key, ps, math.MaxUint64) require.NoError(t, err) b := make([]byte, 30<<20) - rand.Read(b) + _, _ = rand.Read(b) for i := 1; i <= 2; i++ { edge := &pb.DirectedEdge{ ValueId: uint64(i), @@ -994,7 +994,7 @@ func TestLargePlistSplit(t *testing.T) { ol, err = getNew(key, ps, math.MaxUint64) require.NoError(t, err) b = make([]byte, 10<<20) - rand.Read(b) + _, _ = rand.Read(b) for i := 0; i < 63; i++ { edge := &pb.DirectedEdge{ Entity: uint64(1 << uint32(i)), @@ -1028,10 +1028,10 @@ func TestDeleteStarMultiPartList(t *testing.T) { validateCount := func(expected int) { count := 0 - list.Iterate(math.MaxUint64, 0, func(posting *pb.Posting) error { + require.NoError(t, list.Iterate(math.MaxUint64, 0, func(posting *pb.Posting) error { count++ return nil - }) + })) require.Equal(t, expected, count) } validateCount(numEdges) @@ -1152,10 +1152,10 @@ func TestMultiPartListIterAfterUid(t *testing.T) { ol, _ := createMultiPartList(t, size, false) var visitedUids []uint64 - ol.Iterate(uint64(size+1), 50000, func(p *pb.Posting) error { + require.NoError(t, ol.Iterate(uint64(size+1), 50000, func(p *pb.Posting) error { visitedUids = append(visitedUids, p.Uid) return nil - }) + })) require.Equal(t, 50000, len(visitedUids)) for i, uid := range visitedUids { require.Equal(t, uint64(50000+i+1), uid) @@ -1241,10 +1241,10 @@ func TestMultiPartListDelete(t *testing.T) { require.Equal(t, size*2, commits) counter := 0 - ol.Iterate(math.MaxUint64, 0, func(p *pb.Posting) error { + require.NoError(t, ol.Iterate(math.MaxUint64, 0, func(p *pb.Posting) error { counter++ return nil - }) + })) require.Equal(t, 0, counter) kvs, err := ol.Rollup(nil) @@ -1388,7 +1388,9 @@ func TestSingleListRollup(t *testing.T) { var bl pb.BackupPostingList buf := z.NewBuffer(10<<10, "TestSingleListRollup") - defer buf.Release() + defer func() { + require.NoError(t, buf.Release()) + }() kv, err := ol.ToBackupPostingList(&bl, nil, buf) require.NoError(t, err) require.Equal(t, 1, len(kv.UserMeta)) diff --git a/posting/lmap_test.go b/posting/lmap_test.go index 1b1166786b3..2d9b36199be 100644 --- a/posting/lmap_test.go +++ b/posting/lmap_test.go @@ -29,7 +29,7 @@ func BenchmarkGet(b *testing.B) { for pb.Next() { // i := uint64(rand.Int63()) _ = uint64(rand.Int63()) - getNew(key, nil, math.MaxUint64) + _, _ = getNew(key, nil, math.MaxUint64) // lmap.Get(i) } }) diff --git a/query/common_test.go b/query/common_test.go index ad71711540e..13085173166 100644 --- a/query/common_test.go +++ b/query/common_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package query import ( @@ -54,7 +55,11 @@ func dropPredicate(pred string) { func processQuery(ctx context.Context, t *testing.T, query string) (string, error) { txn := client.NewTxn() - defer txn.Discard(ctx) + defer func() { + if err := txn.Discard(ctx); err != nil { + t.Logf("error discarding txn: %v", err) + } + }() res, err := txn.Query(ctx, query) if err != nil { @@ -71,7 +76,7 @@ func processQuery(ctx context.Context, t *testing.T, query string) (string, erro func processQueryRDF(ctx context.Context, t *testing.T, query string) (string, error) { txn := client.NewTxn() - defer txn.Discard(ctx) + defer func() { _ = txn.Discard(ctx) }() res, err := txn.Do(ctx, &api.Request{ Query: query, @@ -92,7 +97,7 @@ func processQueryNoErr(t *testing.T, query string) string { // processQueryForMetrics works like processQuery but returns metrics instead of response. func processQueryForMetrics(t *testing.T, query string) *api.Metrics { txn := client.NewTxn() - defer txn.Discard(context.Background()) + defer func() { _ = txn.Discard(context.Background()) }() res, err := txn.Query(context.Background(), query) require.NoError(t, err) @@ -102,7 +107,7 @@ func processQueryForMetrics(t *testing.T, query string) *api.Metrics { func processQueryWithVars(t *testing.T, query string, vars map[string]string) (string, error) { txn := client.NewTxn() - defer txn.Discard(context.Background()) + defer func() { _ = txn.Discard(context.Background()) }() res, err := txn.QueryWithVars(context.Background(), query, vars) if err != nil { @@ -120,7 +125,7 @@ func processQueryWithVars(t *testing.T, query string, func addTriplesToCluster(triples string) error { txn := client.NewTxn() ctx := context.Background() - defer txn.Discard(ctx) + defer func() { _ = txn.Discard(ctx) }() _, err := txn.Mutate(ctx, &api.Mutation{ SetNquads: []byte(triples), @@ -132,7 +137,7 @@ func addTriplesToCluster(triples string) error { func deleteTriplesInCluster(triples string) { txn := client.NewTxn() ctx := context.Background() - defer txn.Discard(ctx) + defer func() { _ = txn.Discard(ctx) }() _, err := txn.Mutate(ctx, &api.Mutation{ DelNquads: []byte(triples), @@ -342,15 +347,16 @@ age2 : int @index(int) . ` func populateCluster() { - err := client.Alter(context.Background(), &api.Operation{DropAll: true}) - if err != nil { + if err := client.Alter(context.Background(), &api.Operation{DropAll: true}); err != nil { panic(fmt.Sprintf("Could not perform DropAll op. Got error %v", err.Error())) } setSchema(testSchema) - testutil.AssignUids(100000) + if err := testutil.AssignUids(100000); err != nil { + panic(fmt.Sprintf("Could not perform DropAll op. Got error %v", err.Error())) + } - err = addTriplesToCluster(` + err := addTriplesToCluster(` <1> "Michonne" . <2> "King Lear" . <3> "Margaret" . diff --git a/query/fastjson_test.go b/query/fastjson_test.go index 791d36b2ab3..0aa72320b98 100644 --- a/query/fastjson_test.go +++ b/query/fastjson_test.go @@ -69,11 +69,11 @@ func TestEncode(t *testing.T) { t.Run("with uid list predicate", func(t *testing.T) { root := enc.newNode(0) friendNode1 := enc.newNode(enc.idForAttr("friend")) - enc.AddValue(friendNode1, enc.idForAttr("name"), - types.Val{Tid: types.StringID, Value: "alice"}) + require.NoError(t, enc.AddValue(friendNode1, enc.idForAttr("name"), + types.Val{Tid: types.StringID, Value: "alice"})) friendNode2 := enc.newNode(enc.idForAttr("friend")) - enc.AddValue(friendNode2, enc.idForAttr("name"), - types.Val{Tid: types.StringID, Value: "bob"}) + require.NoError(t, enc.AddValue(friendNode2, enc.idForAttr("name"), + types.Val{Tid: types.StringID, Value: "bob"})) enc.AddListChild(root, friendNode1) enc.AddListChild(root, friendNode2) @@ -96,10 +96,10 @@ func TestEncode(t *testing.T) { t.Run("with value list predicate", func(t *testing.T) { root := enc.newNode(0) - enc.AddValue(root, enc.idForAttr("name"), - types.Val{Tid: types.StringID, Value: "alice"}) - enc.AddValue(root, enc.idForAttr("name"), - types.Val{Tid: types.StringID, Value: "bob"}) + require.NoError(t, enc.AddValue(root, enc.idForAttr("name"), + types.Val{Tid: types.StringID, Value: "alice"})) + require.NoError(t, enc.AddValue(root, enc.idForAttr("name"), + types.Val{Tid: types.StringID, Value: "bob"})) enc.buf.Reset() require.NoError(t, enc.encode(root)) @@ -117,9 +117,8 @@ func TestEncode(t *testing.T) { root := enc.newNode(0) person := enc.newNode(enc.idForAttr("person")) - enc.AddValue(person, enc.idForAttr("name"), types.Val{Tid: types.StringID, Value: "alice"}) - enc.AddValue(person, enc.idForAttr("age"), types.Val{Tid: types.IntID, Value: 25}) - + require.NoError(t, enc.AddValue(person, enc.idForAttr("name"), types.Val{Tid: types.StringID, Value: "alice"})) + require.NoError(t, enc.AddValue(person, enc.idForAttr("age"), types.Val{Tid: types.IntID, Value: 25})) enc.AddListChild(root, person) enc.buf.Reset() diff --git a/query/outputnode_test.go b/query/outputnode_test.go index 7a8bddfd8ce..4e29d616f7e 100644 --- a/query/outputnode_test.go +++ b/query/outputnode_test.go @@ -45,8 +45,8 @@ func TestEncodeMemory(t *testing.T) { n := enc.newNode(0) require.NotNil(t, n) for i := 0; i < 15000; i++ { - enc.AddValue(n, enc.idForAttr(fmt.Sprintf("very long attr name %06d", i)), - types.ValueForType(types.StringID)) + require.NoError(t, enc.AddValue(n, enc.idForAttr(fmt.Sprintf("very long attr name %06d", i)), + types.ValueForType(types.StringID))) enc.AddListChild(n, enc.newNode(enc.idForAttr(fmt.Sprintf("another long child %06d", i)))) } @@ -55,7 +55,7 @@ func TestEncodeMemory(t *testing.T) { defer wg.Done() for j := 0; j < 1000; j++ { enc.buf.Reset() - enc.encode(n) + require.NoError(t, enc.encode(n)) } }() } @@ -75,25 +75,25 @@ func TestNormalizeJSONLimit(t *testing.T) { n := enc.newNode(enc.idForAttr("root")) require.NotNil(t, n) for i := 0; i < 1000; i++ { - enc.AddValue(n, enc.idForAttr(fmt.Sprintf("very long attr name %06d", i)), - types.ValueForType(types.StringID)) + require.NoError(t, enc.AddValue(n, enc.idForAttr(fmt.Sprintf("very long attr name %06d", i)), + types.ValueForType(types.StringID))) child1 := enc.newNode(enc.idForAttr("child1")) enc.AddListChild(n, child1) for j := 0; j < 100; j++ { - enc.AddValue(child1, enc.idForAttr(fmt.Sprintf("long child1 attr %06d", j)), - types.ValueForType(types.StringID)) + require.NoError(t, enc.AddValue(child1, enc.idForAttr(fmt.Sprintf("long child1 attr %06d", j)), + types.ValueForType(types.StringID))) } child2 := enc.newNode(enc.idForAttr("child2")) enc.AddListChild(n, child2) for j := 0; j < 100; j++ { - enc.AddValue(child2, enc.idForAttr(fmt.Sprintf("long child2 attr %06d", j)), - types.ValueForType(types.StringID)) + require.NoError(t, enc.AddValue(child2, enc.idForAttr(fmt.Sprintf("long child2 attr %06d", j)), + types.ValueForType(types.StringID))) } child3 := enc.newNode(enc.idForAttr("child3")) enc.AddListChild(n, child3) for j := 0; j < 100; j++ { - enc.AddValue(child3, enc.idForAttr(fmt.Sprintf("long child3 attr %06d", j)), - types.ValueForType(types.StringID)) + require.NoError(t, enc.AddValue(child3, enc.idForAttr(fmt.Sprintf("long child3 attr %06d", j)), + types.ValueForType(types.StringID))) } } _, err := enc.normalize(n) diff --git a/query/query0_test.go b/query/query0_test.go index 862500e33b4..c8725c2b20b 100644 --- a/query/query0_test.go +++ b/query/query0_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package query import ( diff --git a/query/query1_test.go b/query/query1_test.go index fbd9e31e09c..72df067068b 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package query import ( diff --git a/query/query2_test.go b/query/query2_test.go index 4c223e8c4e3..196f06c1b4e 100644 --- a/query/query2_test.go +++ b/query/query2_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package query import ( diff --git a/query/query3_test.go b/query/query3_test.go index 258660b9655..2d46a9f6f7b 100644 --- a/query/query3_test.go +++ b/query/query3_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package query import ( diff --git a/query/query_facets_test.go b/query/query_facets_test.go index 7802a80e209..60c997afd7d 100644 --- a/query/query_facets_test.go +++ b/query/query_facets_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package query import ( @@ -107,7 +108,7 @@ func populateClusterWithFacets() error { } func TestFacetsVarAllofterms(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -127,7 +128,7 @@ func TestFacetsVarAllofterms(t *testing.T) { } func TestFacetsWithVarEq(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find family of 1 query := ` query works($family : bool = true){ @@ -148,7 +149,7 @@ func TestFacetsWithVarEq(t *testing.T) { } func TestFacetWithVarLe(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` query works($age : int = 35) { @@ -169,7 +170,7 @@ func TestFacetWithVarLe(t *testing.T) { } func TestFacetWithVarGt(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` query works($age : int = "32") { @@ -190,7 +191,7 @@ func TestFacetWithVarGt(t *testing.T) { } func TestRetrieveFacetsSimple(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(0x1)) { @@ -207,7 +208,7 @@ func TestRetrieveFacetsSimple(t *testing.T) { } func TestOrderFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // to see how friend @facets are positioned in output. query := ` { @@ -251,7 +252,7 @@ func TestOrderFacets(t *testing.T) { } func TestOrderdescFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // to see how friend @facets are positioned in output. query := ` { @@ -295,7 +296,7 @@ func TestOrderdescFacets(t *testing.T) { } func TestOrderdescFacetsWithFilters(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { @@ -343,7 +344,7 @@ func TestOrderdescFacetsWithFilters(t *testing.T) { } func TestFacetsMultipleOrderby(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(33)) { @@ -386,7 +387,7 @@ func TestFacetsMultipleOrderby(t *testing.T) { } func TestFacetsMultipleOrderbyMultipleUIDs(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(33, 34)) { @@ -445,7 +446,7 @@ func TestFacetsMultipleOrderbyMultipleUIDs(t *testing.T) { } func TestFacetsMultipleOrderbyNonsortableFacet(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(33)) { @@ -491,7 +492,7 @@ func TestFacetsMultipleOrderbyNonsortableFacet(t *testing.T) { } func TestFacetsMultipleOrderbyAllFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(33)) { @@ -540,7 +541,7 @@ func TestFacetsMultipleOrderbyAllFacets(t *testing.T) { // This test tests multiple order by on facets where some facets in not present in all records. func TestFacetsMultipleOrderbyMissingFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(33)) { @@ -582,7 +583,7 @@ func TestFacetsMultipleOrderbyMissingFacets(t *testing.T) { } func TestRetrieveFacetsAsVars(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // to see how friend @facets are positioned in output. query := ` { @@ -604,7 +605,7 @@ func TestRetrieveFacetsAsVars(t *testing.T) { } func TestRetrieveFacetsUidValues(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // to see how friend @facets are positioned in output. query := ` { @@ -658,7 +659,7 @@ func TestRetrieveFacetsUidValues(t *testing.T) { } func TestRetrieveFacetsAll(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(0x1)) { @@ -719,7 +720,7 @@ func TestRetrieveFacetsAll(t *testing.T) { } func TestFacetsNotInQuery(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(0x1)) { @@ -740,7 +741,7 @@ func TestFacetsNotInQuery(t *testing.T) { } func TestSubjectWithNoFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // id 33 does not have any facets associated with name and school query := ` { @@ -759,7 +760,7 @@ func TestSubjectWithNoFacets(t *testing.T) { } func TestFetchingFewFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // only 1 friend of 1 has facet : "close" and she/he has no name query := ` { @@ -803,7 +804,7 @@ func TestFetchingFewFacets(t *testing.T) { } func TestFetchingNoFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // TestFetchingFewFacets but without the facet. Returns no facets. query := ` { @@ -823,7 +824,7 @@ func TestFetchingNoFacets(t *testing.T) { } func TestFacetsSortOrder(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // order of facets in dql query should not matter. query := ` { @@ -869,7 +870,7 @@ func TestFacetsSortOrder(t *testing.T) { } func TestUnknownFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // uknown facets should be ignored. query := ` { @@ -889,7 +890,7 @@ func TestUnknownFacets(t *testing.T) { } func TestFacetsMutation(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // Delete friendship between Michonne and Glenn deleteTriplesInCluster("<1> <24> .") @@ -944,7 +945,7 @@ func TestFacetsMutation(t *testing.T) { } func TestFacetsFilterSimple(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find close friends of 1 query := ` { @@ -966,7 +967,7 @@ func TestFacetsFilterSimple(t *testing.T) { } func TestFacetsFilterSimple2(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find close friends of 1 query := ` { @@ -987,7 +988,7 @@ func TestFacetsFilterSimple2(t *testing.T) { } func TestFacetsFilterSimple3(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find close friends of 1 query := ` { @@ -1008,7 +1009,7 @@ func TestFacetsFilterSimple3(t *testing.T) { } func TestFacetsFilterOr(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find close or family friends of 1 query := ` { @@ -1030,7 +1031,7 @@ func TestFacetsFilterOr(t *testing.T) { } func TestFacetsFilterAnd(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // unknown filters do not have any effect on results. query := ` { @@ -1051,7 +1052,7 @@ func TestFacetsFilterAnd(t *testing.T) { } func TestFacetsFilterle(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find friends of 1 below 36 years of age. query := ` { @@ -1072,7 +1073,7 @@ func TestFacetsFilterle(t *testing.T) { } func TestFacetsFilterge(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find friends of 1 above 32 years of age. query := ` { @@ -1093,7 +1094,7 @@ func TestFacetsFilterge(t *testing.T) { } func TestFacetsFilterAndOrle(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find close or family friends of 1 before 2007-01-10 query := ` { @@ -1115,7 +1116,7 @@ func TestFacetsFilterAndOrle(t *testing.T) { } func TestFacetsFilterAndOrge2(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find close or family friends of 1 after 2007-01-10 query := ` { @@ -1136,7 +1137,7 @@ func TestFacetsFilterAndOrge2(t *testing.T) { } func TestFacetsFilterNotAndOrgeMutuallyExclusive(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // find Not (close or family friends of 1 after 2007-01-10) // Mutually exclusive of above result : TestFacetsFilterNotAndOrge query := ` @@ -1158,7 +1159,7 @@ func TestFacetsFilterNotAndOrgeMutuallyExclusive(t *testing.T) { } func TestFacetsFilterUnknownFacets(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // unknown facets should filter out edges. query := ` { @@ -1179,7 +1180,7 @@ func TestFacetsFilterUnknownFacets(t *testing.T) { } func TestFacetsFilterUnknownOrKnown(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // unknown filters with OR do not have any effect on results query := ` { @@ -1200,7 +1201,7 @@ func TestFacetsFilterUnknownOrKnown(t *testing.T) { } func TestFacetsFilterallofterms(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -1220,7 +1221,7 @@ func TestFacetsFilterallofterms(t *testing.T) { } func TestFacetsFilterAllofMultiple(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -1240,7 +1241,7 @@ func TestFacetsFilterAllofMultiple(t *testing.T) { } func TestFacetsFilterAllofNone(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // nothing matches in allofterms query := ` { @@ -1261,7 +1262,7 @@ func TestFacetsFilterAllofNone(t *testing.T) { } func TestFacetsFilteranyofterms(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -1281,7 +1282,7 @@ func TestFacetsFilteranyofterms(t *testing.T) { } func TestFacetsFilterAnyofNone(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -1301,7 +1302,7 @@ func TestFacetsFilterAnyofNone(t *testing.T) { } func TestFacetsFilterAllofanyofterms(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -1321,7 +1322,7 @@ func TestFacetsFilterAllofanyofterms(t *testing.T) { } func TestFacetsFilterAllofAndanyofterms(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(31)) { @@ -1341,7 +1342,7 @@ func TestFacetsFilterAllofAndanyofterms(t *testing.T) { } func TestFacetsFilterAtValueBasic(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1356,7 +1357,7 @@ func TestFacetsFilterAtValueBasic(t *testing.T) { } func TestFacetsFilterAtValueListType(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1370,7 +1371,7 @@ func TestFacetsFilterAtValueListType(t *testing.T) { } func TestFacetsFilterAtValueComplex1(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1385,7 +1386,7 @@ func TestFacetsFilterAtValueComplex1(t *testing.T) { } func TestFacetsFilterAtValueComplex2(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1398,7 +1399,7 @@ func TestFacetsFilterAtValueComplex2(t *testing.T) { } func TestFacetsFilterAtValueWithLangs(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1412,7 +1413,7 @@ func TestFacetsFilterAtValueWithLangs(t *testing.T) { } func TestFacetsFilterAtValueWithBadLang(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1425,7 +1426,7 @@ func TestFacetsFilterAtValueWithBadLang(t *testing.T) { } func TestFacetsFilterAtValueWithFacet(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1441,7 +1442,7 @@ func TestFacetsFilterAtValueWithFacet(t *testing.T) { } func TestFacetsFilterAtValueWithFacetAndLangs(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1455,7 +1456,7 @@ func TestFacetsFilterAtValueWithFacetAndLangs(t *testing.T) { } func TestFacetsFilterAtValueWithDifferentFacet(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: has(name)) { @@ -1471,7 +1472,7 @@ func TestFacetsFilterAtValueWithDifferentFacet(t *testing.T) { } func TestFacetsFilterAndRetrieval(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) // Close should not be retrieved.. only used for filtering. query := ` { @@ -1511,7 +1512,7 @@ func TestFacetsFilterAndRetrieval(t *testing.T) { } func TestFacetWithLang(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(320)) { @@ -1525,7 +1526,7 @@ func TestFacetWithLang(t *testing.T) { } func TestFilterUidFacetMismatch(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(0x1)) { @@ -1558,7 +1559,7 @@ func TestFilterUidFacetMismatch(t *testing.T) { } func TestRecurseFacetOrder(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(1)) @recurse(depth: 2) { @@ -1659,7 +1660,7 @@ func TestRecurseFacetOrder(t *testing.T) { } func TestFacetsAlias(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me(func: uid(0x1)) { @@ -1711,7 +1712,7 @@ func TestFacetsAlias(t *testing.T) { } func TestFacetsAlias2(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := ` { me2(func: uid(0x1)) { @@ -1758,7 +1759,7 @@ func TestTypeExpandFacets(t *testing.T) { } func TestFacetsCascadeScalarPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 23)) @cascade { name @facets @@ -1787,7 +1788,7 @@ func TestFacetsCascadeScalarPredicate(t *testing.T) { } func TestFacetsCascadeUIDPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 23, 24)) @cascade { name @facets @@ -1844,7 +1845,7 @@ func TestFacetsCascadeUIDPredicate(t *testing.T) { } func TestFacetsNestedCascade(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 23)) { name @facets @@ -1901,7 +1902,7 @@ func TestFacetsNestedCascade(t *testing.T) { } func TestFacetsCascadeWithFilter(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 23)) @filter(eq(name, "Michonne")) @cascade { name @facets @@ -1924,7 +1925,7 @@ func TestFacetsCascadeWithFilter(t *testing.T) { } func TestFacetUIDPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(0x1)) { name @@ -1952,7 +1953,7 @@ func TestFacetUIDPredicate(t *testing.T) { } func TestFacetUIDListPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(0x1)) { name @@ -1994,7 +1995,7 @@ func TestFacetUIDListPredicate(t *testing.T) { } func TestFacetValueListPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 12000)) { name@en @facets @@ -2049,7 +2050,7 @@ func TestFacetValueListPredicate(t *testing.T) { } func TestFacetUIDPredicateWithNormalize(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(0x1)) @normalize { name: name @@ -2075,7 +2076,7 @@ func TestFacetUIDPredicateWithNormalize(t *testing.T) { } func TestFacetUIDListPredicateWithNormalize(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(0x1)) @normalize { name: name @@ -2116,7 +2117,7 @@ func TestFacetUIDListPredicateWithNormalize(t *testing.T) { } func TestNestedFacetUIDListPredicateWithNormalize(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(0x1)) @normalize { name: name @@ -2180,7 +2181,7 @@ func TestNestedFacetUIDListPredicateWithNormalize(t *testing.T) { } func TestFacetValuePredicateWithNormalize(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 12000)) @normalize { eng_name: name@en @facets @@ -2235,7 +2236,7 @@ func TestFacetValuePredicateWithNormalize(t *testing.T) { } func TestFacetValueListPredicateSingleFacet(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(0x1)) { alt_name @facets(origin) @@ -2263,7 +2264,7 @@ func TestFacetValueListPredicateSingleFacet(t *testing.T) { } func TestFacetsWithExpand(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(14000)) { @@ -2300,7 +2301,7 @@ func TestFacetsWithExpand(t *testing.T) { } func TestCountFacetsFilteringUidListPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 33)) { @@ -2331,7 +2332,7 @@ func TestCountFacetsFilteringUidListPredicate(t *testing.T) { } func TestCountFacetsFilteringUidPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 33)) { @@ -2362,7 +2363,7 @@ func TestCountFacetsFilteringUidPredicate(t *testing.T) { } func TestCountFacetsFilteringScalarPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 23)) { @@ -2396,7 +2397,7 @@ func TestCountFacetsFilteringScalarPredicate(t *testing.T) { } func TestCountFacetsFilteringScalarListPredicate(t *testing.T) { - populateClusterWithFacets() + require.NoError(t, populateClusterWithFacets()) query := `{ q(func: uid(1, 12000)) { diff --git a/raftwal/storage_test.go b/raftwal/storage_test.go index e0d8859037f..a5ac51bbbbe 100644 --- a/raftwal/storage_test.go +++ b/raftwal/storage_test.go @@ -161,7 +161,7 @@ func TestStorageLastIndex(t *testing.T) { t.Errorf("term = %d, want %d", last, 5) } - ds.reset([]raftpb.Entry{{Index: 6, Term: 5}}) + require.NoError(t, ds.reset([]raftpb.Entry{{Index: 6, Term: 5}})) last, err = ds.LastIndex() if err != nil { t.Errorf("err = %v, want nil", err) @@ -376,7 +376,7 @@ func TestTruncateStorage(t *testing.T) { Type: typ, Data: []byte(fmt.Sprintf("entry %d", idx)), } - ds.addEntries([]raftpb.Entry{entry}) + require.NoError(t, ds.addEntries([]raftpb.Entry{entry})) } // Verify all entries. @@ -412,7 +412,7 @@ func TestTruncateStorage(t *testing.T) { Type: raftpb.EntryNormal, Data: []byte(fmt.Sprintf("entry %d", idx)), } - ds.addEntries([]raftpb.Entry{entry}) + require.NoError(t, ds.addEntries([]raftpb.Entry{entry})) } // Verify all entries. @@ -438,7 +438,7 @@ func TestStorageOnlySnap(t *testing.T) { t.Logf("Creating dir: %s\n", dir) buf := make([]byte, 128) - rand.Read(buf) + _, _ = rand.Read(buf) N := uint64(1000) snap := &raftpb.Snapshot{} @@ -532,7 +532,7 @@ func TestStorageBig(t *testing.T) { check(N, N+1) buf := make([]byte, 128) - rand.Read(buf) + _, _ = rand.Read(buf) cs := &raftpb.ConfState{} require.NoError(t, ds.CreateSnapshot(N-100, cs, buf)) diff --git a/systest/acl/restore/acl_restore_test.go b/systest/acl/restore/acl_restore_test.go index 121adcfed13..c0def2ae1ac 100644 --- a/systest/acl/restore/acl_restore_test.go +++ b/systest/acl/restore/acl_restore_test.go @@ -96,7 +96,7 @@ func TestAclCacheRestore(t *testing.T) { conn, err := grpc.Dial(testutil.SockAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) - dg.Login(context.Background(), "groot", "password") + require.NoError(t, dg.Login(context.Background(), "groot", "password")) sendRestoreRequest(t, "/backups", "vibrant_euclid5", 1) testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) diff --git a/systest/audit/audit_test.go b/systest/audit/audit_test.go index e2c21ab1435..596fa71a764 100644 --- a/systest/audit/audit_test.go +++ b/systest/audit/audit_test.go @@ -71,7 +71,7 @@ func TestAlphaAudit(t *testing.T) { fmt.Sprintf("%s/admin", testutil.SockAddrHttp), "--header", "Content-Type: application/json", "--data-raw", `'{"query":"mutation {\n backup( -input: {destination: \"/Users/sankalanparajuli/work/backup\"}) {\n response {\n message\n code\n }\n }\n}\n","variables":{}}'`}, +input: {destination: \"/Users/sankalanparajuli/work/backup\"}) {\n response {\n message\n code\n }\n }\n}\n","variables":{}}'`}, //nolint:lll "/graphql": {"--location", "--request", "POST", fmt.Sprintf("%s/graphql", testutil.SockAddrHttp), "--header", "Content-Type: application/json", diff --git a/systest/backup/encryption/backup_test.go b/systest/backup/encryption/backup_test.go index 2ee6b1523f2..5a6f4cbd74a 100644 --- a/systest/backup/encryption/backup_test.go +++ b/systest/backup/encryption/backup_test.go @@ -397,7 +397,7 @@ func copyToLocalFs(t *testing.T) { for object := range objectCh2 { require.NoError(t, object.Err) dstFile := backupDir + "/" + object.Key - mc.FGetObject(bucketName, object.Key, dstFile, minio.GetObjectOptions{}) + require.NoError(t, mc.FGetObject(bucketName, object.Key, dstFile, minio.GetObjectOptions{})) } close(lsCh2) } diff --git a/systest/backup/minio/backup_test.go b/systest/backup/minio/backup_test.go index ff331b404e0..4040079182d 100644 --- a/systest/backup/minio/backup_test.go +++ b/systest/backup/minio/backup_test.go @@ -408,7 +408,7 @@ func copyToLocalFs(t *testing.T) { for object := range objectCh2 { require.NoError(t, object.Err) dstFile := backupDir + "/" + object.Key - mc.FGetObject(bucketName, object.Key, dstFile, minio.GetObjectOptions{}) + require.NoError(t, mc.FGetObject(bucketName, object.Key, dstFile, minio.GetObjectOptions{})) } close(lsCh2) } diff --git a/systest/bgindex/count_test.go b/systest/bgindex/count_test.go index 10b6011da50..87868d8071f 100644 --- a/systest/bgindex/count_test.go +++ b/systest/bgindex/count_test.go @@ -67,7 +67,8 @@ func TestCountIndex(t *testing.T) { fmt.Println("inserting values") th := y.NewThrottle(10000) for i := 1; i <= int(numUIDs); i++ { - th.Do() + require.NoError(t, th.Do()) + go func(uid int) { defer th.Done(nil) bb := &bytes.Buffer{} @@ -86,7 +87,7 @@ func TestCountIndex(t *testing.T) { } }(i) } - th.Finish() + require.NoError(t, th.Finish()) fmt.Println("building indexes in background") if err := dg.Alter(context.Background(), &api.Operation{ @@ -250,7 +251,7 @@ func TestCountIndex(t *testing.T) { fmt.Println("starting to query") var count uint64 th = y.NewThrottle(50000) - th.Do() + require.NoError(t, th.Do()) go func() { defer th.Done(nil) for { @@ -264,7 +265,7 @@ func TestCountIndex(t *testing.T) { }() for value, uids := range countIndex { - th.Do() + require.NoError(t, th.Do()) go func(val int, uidList []int) { defer th.Done(nil) if val <= 0 { @@ -281,7 +282,7 @@ func TestCountIndex(t *testing.T) { atomic.AddUint64(&count, 1) }(value, uids) } - th.Finish() + require.NoError(t, th.Finish()) close(ch) for p := range ch { diff --git a/systest/bgindex/parallel_test.go b/systest/bgindex/parallel_test.go index bb5cb2228fe..147e5c37d63 100644 --- a/systest/bgindex/parallel_test.go +++ b/systest/bgindex/parallel_test.go @@ -182,7 +182,7 @@ func TestParallelIndexing(t *testing.T) { fmt.Println("starting to query") var count uint64 th := y.NewThrottle(50000) - th.Do() + require.NoError(t, th.Do()) go func() { defer th.Done(nil) for { @@ -202,7 +202,7 @@ func TestParallelIndexing(t *testing.T) { ch := make(chan pair, total*3) for _, predicate := range []string{"balance_str", "balance_int", "balance_float"} { for i := 1; i <= total; i++ { - th.Do() + require.NoError(t, th.Do()) go func(bal int, pred string) { defer th.Done(nil) if err := checkBalance(bal, pred); err != nil { @@ -212,7 +212,7 @@ func TestParallelIndexing(t *testing.T) { }(i, predicate) } } - th.Finish() + require.NoError(t, th.Finish()) close(ch) for p := range ch { diff --git a/systest/bgindex/string_test.go b/systest/bgindex/string_test.go index 581c6b1d4ba..97c36995a6d 100644 --- a/systest/bgindex/string_test.go +++ b/systest/bgindex/string_test.go @@ -239,7 +239,7 @@ func TestStringIndex(t *testing.T) { fmt.Println("starting to query") var count uint64 th := y.NewThrottle(50000) - th.Do() + require.NoError(t, th.Do()) go func() { defer th.Done(nil) for { @@ -253,7 +253,7 @@ func TestStringIndex(t *testing.T) { }() for balance, uids := range balIndex { - th.Do() + require.NoError(t, th.Do()) go func(bal int, uidList []int) { defer th.Done(nil) if bal == -1 { @@ -270,7 +270,7 @@ func TestStringIndex(t *testing.T) { atomic.AddUint64(&count, 1) }(balance, uids) } - th.Finish() + require.NoError(t, th.Finish()) close(ch) for p := range ch { diff --git a/systest/bulk_live/common/bulk_live_cases.go b/systest/bulk_live/common/bulk_live_cases.go index 5ae36596162..cf278888e63 100644 --- a/systest/bulk_live/common/bulk_live_cases.go +++ b/systest/bulk_live/common/bulk_live_cases.go @@ -705,8 +705,7 @@ func testDeleteEdgeWithStar(t *testing.T) { } -func testGqlSchema(t *testing.T) { - t.Skipf("Skipping: This is failing for some reason. Please fix this.") +func TestGqlSchema(t *testing.T) { s := newBulkOnlySuite(t, "", "", "abc") defer s.cleanup(t) @@ -728,8 +727,7 @@ func testGqlSchema(t *testing.T) { } -// TODO: Fix this later. -func DONOTRUNTestGoldenData(t *testing.T) { +func TestGoldenData(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode") } diff --git a/systest/export/export_test.go b/systest/export/export_test.go index cf538558ed6..c590a31da37 100644 --- a/systest/export/export_test.go +++ b/systest/export/export_test.go @@ -49,7 +49,7 @@ var ( func TestExportSchemaToMinio(t *testing.T) { mc, err := testutil.NewMinioClient() require.NoError(t, err) - mc.MakeBucket(bucketName, "") + require.NoError(t, mc.MakeBucket(bucketName, "")) setupDgraph(t, moviesData, movieSchema) requestExport(t, minioDest, "rdf") diff --git a/systest/license/license_test.go b/systest/license/license_test.go index 5b095ef9235..94018797fc0 100644 --- a/systest/license/license_test.go +++ b/systest/license/license_test.go @@ -113,7 +113,7 @@ func TestEnterpriseLicense(t *testing.T) { invalidKey, ``, ``, - `while extracting enterprise details from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, + `while extracting enterprise details from the license: while reading PGP message from license file: openpgp: unsupported feature: public key version`, //nolint:lll }, { "Using empty entrerprise license key should return an error", diff --git a/systest/live_pw_test.go b/systest/live_pw_test.go index 3458b2149b9..ea414ad468c 100644 --- a/systest/live_pw_test.go +++ b/systest/live_pw_test.go @@ -128,7 +128,7 @@ func PasswordImport(t *testing.T, c *dgo.Dgraph) { require.JSONEq(t, fmt.Sprintf(`{"q":[{"secret":%t}]}`, uid == assigned.Uids["uid2"]), string(resp.Json)) } - txn.Discard(ctx) + require.NoError(t, txn.Discard(ctx)) resp, err := c.NewTxn().Query(ctx, ` { diff --git a/systest/mutations_test.go b/systest/mutations_test.go index bb4f538f56b..d6e0c8e8837 100644 --- a/systest/mutations_test.go +++ b/systest/mutations_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package main import ( @@ -544,7 +545,7 @@ func LangAndSortBugTest(t *testing.T, c *dgo.Dgraph) { require.NoError(t, err) txn = c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() resp, err := txn.Query(ctx, ` { q(func: eq(name, "Michael")) { @@ -995,14 +996,14 @@ func DeleteWithExpandAll(t *testing.T, c *dgo.Dgraph) { var r Root resp, err := c.NewTxn().QueryWithVars(ctx, q, map[string]string{"$id": auid}) require.NoError(t, err) - json.Unmarshal(resp.Json, &r) + require.NoError(t, json.Unmarshal(resp.Json, &r)) // S P O deletion shouldn't delete "to" . require.Equal(t, 1, len(r.Me[0])) // b should not have any predicates. resp, err = c.NewTxn().QueryWithVars(ctx, q, map[string]string{"$id": buid}) require.NoError(t, err) - json.Unmarshal(resp.Json, &r) + require.NoError(t, json.Unmarshal(resp.Json, &r)) require.Equal(t, 0, len(r.Me)) } @@ -1139,7 +1140,7 @@ func ListGeoFilterTest(t *testing.T, c *dgo.Dgraph) { require.NoError(t, c.Alter(ctx, op)) txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() _, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, SetNquads: []byte(` @@ -1187,7 +1188,7 @@ func ListRegexFilterTest(t *testing.T, c *dgo.Dgraph) { require.NoError(t, c.Alter(ctx, op)) txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() _, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, SetNquads: []byte(` @@ -1235,7 +1236,7 @@ func RegexQueryWithVars(t *testing.T, c *dgo.Dgraph) { require.NoError(t, c.Alter(ctx, op)) txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() _, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, SetNquads: []byte(` @@ -1279,7 +1280,7 @@ func GraphQLVarChild(t *testing.T, c *dgo.Dgraph) { require.NoError(t, c.Alter(ctx, op)) txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() au, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, SetNquads: []byte(` @@ -1380,7 +1381,7 @@ func MathGe(t *testing.T, c *dgo.Dgraph) { require.NoError(t, c.Alter(ctx, op)) txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() _, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, SetNquads: []byte(` @@ -1416,7 +1417,7 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) { ctx := context.Background() txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() assigned, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, @@ -1461,7 +1462,7 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) { } txn = c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() uids := getUids(txn) require.Equal(t, 3, len(uids)) for _, uid := range uids { @@ -1479,7 +1480,7 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) { require.NoError(t, err) txn = c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() uids = getUids(txn) require.Equal(t, 2, len(uids)) for _, uid := range uids { @@ -1504,7 +1505,7 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) { } txn = c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() uids = getUids(txn) require.Equal(t, 3, len(uids)) for _, uid := range uids { @@ -1518,7 +1519,7 @@ func HasReverseEdge(t *testing.T, c *dgo.Dgraph) { op := &api.Operation{Schema: `follow: [uid] @reverse .`} require.NoError(t, c.Alter(ctx, op)) txn := c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() _, err := txn.Mutate(ctx, &api.Mutation{ CommitNow: true, @@ -1537,7 +1538,7 @@ func HasReverseEdge(t *testing.T, c *dgo.Dgraph) { } txn = c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() resp, err := txn.Query(ctx, `{ fwd(func: has(follow)) { name } rev(func: has(~follow)) { name } @@ -1589,7 +1590,7 @@ func MaxPredicateSize(t *testing.T, c *dgo.Dgraph) { // Do the same thing as above but for the predicates in DelNquads. txn = c.NewTxn() - defer txn.Discard(ctx) + defer func() { require.NoError(t, txn.Discard(ctx)) }() _, err = txn.Mutate(ctx, &api.Mutation{ CommitNow: true, DelNquads: []byte(fmt.Sprintf(`_:test <%s> "value" .`, largePred)), diff --git a/systest/queries_test.go b/systest/queries_test.go index 671af79ed74..f13c3799f6c 100644 --- a/systest/queries_test.go +++ b/systest/queries_test.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package main import ( diff --git a/t/t.go b/t/t.go index 8984c60dbbc..bfbffccb9c6 100644 --- a/t/t.go +++ b/t/t.go @@ -308,7 +308,7 @@ func runTestsFor(ctx context.Context, pkg, prefix string) error { } dur := time.Since(start).Round(time.Second) - tid, _ := ctx.Value("threadId").(int32) + tid, _ := ctx.Value(_threadIdKey{}).(int32) oc.Took(tid, pkg, dur) fmt.Printf("Ran tests for package: %s in %s\n", pkg, dur) if *runCoverage { @@ -342,6 +342,8 @@ func hasTestFiles(pkg string) bool { return hasTests } +type _threadIdKey struct{} + var _threadId int32 func runTests(taskCh chan task, closer *z.Closer) error { @@ -387,7 +389,7 @@ func runTests(taskCh chan task, closer *z.Closer) error { defer stop() ctx := closer.Ctx() - ctx = context.WithValue(ctx, "threadId", threadId) + ctx = context.WithValue(ctx, _threadIdKey{}, threadId) for task := range taskCh { if ctx.Err() != nil { diff --git a/testutil/graphql.go b/testutil/graphql.go index 1ee33d2b331..16a82580797 100644 --- a/testutil/graphql.go +++ b/testutil/graphql.go @@ -14,6 +14,7 @@ * limitations under the License. */ +//nolint:lll package testutil import ( diff --git a/tok/tok.go b/tok/tok.go index 874c238a267..4fa76de8c3f 100644 --- a/tok/tok.go +++ b/tok/tok.go @@ -292,7 +292,8 @@ func (t TermTokenizer) Tokens(v interface{}) ([]string, error) { lang := LangBase(t.lang) switch lang { case "zh", "ja", "th", "lo", "my", "bo", "km", "kxm": - // Chinese, Japanese, Thai, Lao, Burmese, Tibetan and Khmer (km, kxm) do not use spaces as delimiters. We simply split by space. + // Chinese, Japanese, Thai, Lao, Burmese, Tibetan and Khmer (km, kxm) + // do not use spaces as delimiters. We simply split by space. tokens := strings.Split(str, " ") return x.RemoveDuplicates(tokens), nil default: diff --git a/types/s2index_test.go b/types/s2index_test.go index 8a5cdeeba17..e18ea1ee64c 100644 --- a/types/s2index_test.go +++ b/types/s2index_test.go @@ -213,7 +213,7 @@ func BenchmarkKeyGeneratorPoint(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - IndexGeoTokens(g) + _, _ = IndexGeoTokens(g) } } @@ -235,7 +235,7 @@ func BenchmarkKeyGeneratorPolygon(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - IndexGeoTokens(g) + _, _ = IndexGeoTokens(g) } } diff --git a/types/scalar_types_test.go b/types/scalar_types_test.go index 614de7e730f..4a798c9534d 100644 --- a/types/scalar_types_test.go +++ b/types/scalar_types_test.go @@ -163,10 +163,10 @@ func TestParseTimeNonRFC3339(t *testing.T) { func BenchmarkParseTime(b *testing.B) { for i := 0; i < b.N; i++ { for _, tc := range datesWithTz { - ParseTime(tc.in) + _, _ = ParseTime(tc.in) } for _, tc := range datesWithoutTz { - ParseTime(tc.in) + _, _ = ParseTime(tc.in) } } } @@ -174,7 +174,7 @@ func BenchmarkParseTime(b *testing.B) { func BenchmarkParseTimeRejections(b *testing.B) { for i := 0; i < b.N; i++ { for _, invalidDate := range invalidDates { - ParseTime(invalidDate) + _, _ = ParseTime(invalidDate) } } } diff --git a/upgrade/change_v21.03.0.go b/upgrade/change_v21.03.0.go index 9190e17c91a..2216ff7322f 100644 --- a/upgrade/change_v21.03.0.go +++ b/upgrade/change_v21.03.0.go @@ -292,7 +292,7 @@ func getData(db *badger.DB, attr string, fn func(item *badger.Item) error) error if err := fn(item); err != nil { return err } - break + break //nolint:staticcheck } return nil }) diff --git a/worker/export_test.go b/worker/export_test.go index 457fdac6224..79d0e2925ae 100644 --- a/worker/export_test.go +++ b/worker/export_test.go @@ -202,7 +202,8 @@ func checkExportSchema(t *testing.T, schemaFileList []string) { r, err := gzip.NewReader(f) require.NoError(t, err) var buf bytes.Buffer - buf.ReadFrom(r) + _, err = buf.ReadFrom(r) + require.NoError(t, err) result, err := schema.Parse(buf.String()) require.NoError(t, err) @@ -226,7 +227,8 @@ func checkExportGqlSchema(t *testing.T, gqlSchemaFiles []string) { r, err := gzip.NewReader(f) require.NoError(t, err) var buf bytes.Buffer - buf.ReadFrom(r) + _, err = buf.ReadFrom(r) + require.NoError(t, err) expected := []x.ExportedGQLSchema{{Namespace: x.GalaxyNamespace, Schema: gqlSchema}} b, err := json.Marshal(expected) require.NoError(t, err) diff --git a/worker/snapshot_test.go b/worker/snapshot_test.go index 3a9a83aba8f..0fdcab31a56 100644 --- a/worker/snapshot_test.go +++ b/worker/snapshot_test.go @@ -103,7 +103,8 @@ func TestSnapshot(t *testing.T) { require.NoError(t, err) } const testSchema = "type Person { name: String }" - // uploading new schema while alpha2 is not running so we can test whether the stopped alpha gets new schema in snapshot + // uploading new schema while alpha2 is not running so we can + // test whether the stopped alpha gets new schema in snapshot testutil.UpdateGQLSchema(t, testutil.SockAddrHttp, testSchema) _ = waitForSnapshot(t, snapshotTs) diff --git a/x/error_test.go b/x/error_test.go index 37c33a8e529..6378590a03e 100644 --- a/x/error_test.go +++ b/x/error_test.go @@ -18,12 +18,16 @@ package x import ( "flag" + "fmt" "os" "testing" ) func TestMain(m *testing.M) { flag.Parse() - flag.Set("debugmode", "true") + if err := flag.Set("debugmode", "true"); err != nil { + fmt.Printf("error setting debug mode: %v\n", err) + } + os.Exit(m.Run()) } diff --git a/x/x.go b/x/x.go index b282be561d8..e4944d0ca0b 100644 --- a/x/x.go +++ b/x/x.go @@ -47,7 +47,7 @@ import ( "github.com/spf13/viper" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/trace" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" @@ -1119,7 +1119,7 @@ func AskUserPassword(userid string, pwdType string, times int) (string, error) { AssertTrue(pwdType == "Current" || pwdType == "New") // ask for the user's password fmt.Printf("%s password for %v:", pwdType, userid) - pd, err := terminal.ReadPassword(int(syscall.Stdin)) + pd, err := term.ReadPassword(int(syscall.Stdin)) if err != nil { return "", errors.Wrapf(err, "while reading password") } @@ -1128,7 +1128,7 @@ func AskUserPassword(userid string, pwdType string, times int) (string, error) { if times == 2 { fmt.Printf("Retype %s password for %v:", strings.ToLower(pwdType), userid) - pd2, err := terminal.ReadPassword(int(syscall.Stdin)) + pd2, err := term.ReadPassword(int(syscall.Stdin)) if err != nil { return "", errors.Wrapf(err, "while reading password") }