docker/swarmkit

View on GitHub
manager/state/raft/testutils/testutils.go

Summary

Maintainability
C
1 day
Test Coverage

File testutils.go has 533 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package testutils

import (
    "context"
    "net"
Severity: Minor
Found in manager/state/raft/testutils/testutils.go - About 2 hrs to fix

    Function WaitForCluster has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
    Open

    func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode) {
        err := testutils.PollFunc(clockSource, func() error {
            var prev *etcdraft.Status
            var leadNode *TestNode
        nodeLoop:
    Severity: Minor
    Found in manager/state/raft/testutils/testutils.go - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function CheckValuesOnNodes has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
    Open

    func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
        iteration := 0
        for checkNodeID, node := range checkNodes {
            assert.NoError(t, testutils.PollFunc(clockSource, func() error {
                var err error
    Severity: Minor
    Found in manager/state/raft/testutils/testutils.go - About 45 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function CopyNode has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    func CopyNode(t *testing.T, clockSource *fakeclock.FakeClock, oldNode *TestNode, forceNewCluster bool, kr *SimpleKeyRotator) (*TestNode, context.Context) {
    Severity: Minor
    Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

      Function CheckValuesOnNodes has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
      Severity: Minor
      Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

        Function NewJoinNode has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func NewJoinNode(t *testing.T, clockSource *fakeclock.FakeClock, join string, tc *cautils.TestCA, opts ...raft.NodeOptions) *TestNode {
        Severity: Minor
        Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

          Function AddRaftNode has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func AddRaftNode(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode, tc *cautils.TestCA, opts ...raft.NodeOptions) {
          Severity: Minor
          Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

            Function CheckValuesOnNodes has 5 return statements (exceeds 4 allowed).
            Open

            func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
                iteration := 0
                for checkNodeID, node := range checkNodes {
                    assert.NoError(t, testutils.PollFunc(clockSource, func() error {
                        var err error
            Severity: Major
            Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

              Function WaitForCluster has 5 return statements (exceeds 4 allowed).
              Open

              func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode) {
                  err := testutils.PollFunc(clockSource, func() error {
                      var prev *etcdraft.Status
                      var leadNode *TestNode
                  nodeLoop:
              Severity: Major
              Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

                There are no issues that match your filters.

                Category
                Status