• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dgraph-io / dgraph / 5942198167

22 Aug 2023 05:37PM UTC coverage: 67.079% (+0.4%) from 66.692%
5942198167

push

web-flow
chore: fix linter warnings after golanci upgrade (#8967)

4 of 4 new or added lines in 1 file covered. (100.0%)

58458 of 87148 relevant lines covered (67.08%)

2204396.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.31
/graphql/admin/removeNode.go
1
/*
2
 * Copyright 2023 Dgraph Labs, Inc. and Contributors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package admin
18

19
import (
20
        "context"
21
        "encoding/json"
22
        "fmt"
23
        "strconv"
24

25
        "github.com/pkg/errors"
26

27
        "github.com/dgraph-io/dgraph/graphql/resolve"
28
        "github.com/dgraph-io/dgraph/graphql/schema"
29
        "github.com/dgraph-io/dgraph/protos/pb"
30
        "github.com/dgraph-io/dgraph/worker"
31
)
32

33
type removeNodeInput struct {
34
        NodeId  uint64
35
        GroupId uint32
36
}
37

38
func resolveRemoveNode(ctx context.Context, m schema.Mutation) (*resolve.Resolved, bool) {
1✔
39
        input, err := getRemoveNodeInput(m)
1✔
40
        if err != nil {
1✔
41
                return resolve.EmptyResult(m, err), false
×
42
        }
×
43

44
        if _, err = worker.RemoveNodeOverNetwork(ctx, &pb.RemoveNodeRequest{NodeId: input.NodeId,
1✔
45
                GroupId: input.GroupId}); err != nil {
2✔
46
                return resolve.EmptyResult(m, err), false
1✔
47
        }
1✔
48

49
        return resolve.DataResult(m,
×
50
                map[string]interface{}{m.Name(): response("Success",
×
51
                        fmt.Sprintf("Removed node with group: %v, idx: %v", input.GroupId, input.NodeId))},
×
52
                nil,
×
53
        ), true
×
54
}
55

56
func getRemoveNodeInput(m schema.Mutation) (*removeNodeInput, error) {
1✔
57
        inputArg, ok := m.ArgValue(schema.InputArgName).(map[string]interface{})
1✔
58
        if !ok {
1✔
59
                return nil, inputArgError(errors.Errorf("can't convert input to map"))
×
60
        }
×
61

62
        inputRef := &removeNodeInput{}
1✔
63
        nodeId, err := parseAsUint64(inputArg["nodeId"])
1✔
64
        if err != nil {
1✔
65
                return nil, inputArgError(schema.GQLWrapf(err, "can't convert input.nodeId to uint64"))
×
66
        }
×
67
        inputRef.NodeId = nodeId
1✔
68

1✔
69
        gId, err := parseAsUint32(inputArg["groupId"])
1✔
70
        if err != nil {
1✔
71
                return nil, inputArgError(schema.GQLWrapf(err, "can't convert input.groupId to uint32"))
×
72
        }
×
73
        inputRef.GroupId = gId
1✔
74

1✔
75
        return inputRef, nil
1✔
76
}
77

78
func parseAsUint64(val interface{}) (uint64, error) {
2✔
79
        return parseAsUint(val, 64)
2✔
80
}
2✔
81

82
func parseAsUint32(val interface{}) (uint32, error) {
2✔
83
        ret, err := parseAsUint(val, 32)
2✔
84
        return uint32(ret), err
2✔
85
}
2✔
86

87
func parseAsUint(val interface{}, bitSize int) (uint64, error) {
4✔
88
        ret := uint64(0)
4✔
89
        var err error
4✔
90

4✔
91
        switch v := val.(type) {
4✔
92
        case string:
4✔
93
                ret, err = strconv.ParseUint(v, 10, bitSize)
4✔
94
        case json.Number:
×
95
                ret, err = strconv.ParseUint(v.String(), 10, bitSize)
×
96
        default:
×
97
                err = errors.Errorf("got unexpected value type")
×
98
        }
99

100
        return ret, err
4✔
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc