asteris-llc/converge

View on GitHub
resource/group/group_test.go

Summary

Maintainability
F
1 wk
Test Coverage

Function TestCheck has a Cognitive Complexity of 124 (exceeds 20 allowed). Consider refactoring.
Open

func TestCheck(t *testing.T) {
    t.Parallel()

    t.Run("state=present", func(t *testing.T) {
        g := group.NewGroup(new(group.System))
Severity: Minor
Found in resource/group/group_test.go - About 2 days 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 TestApply has 431 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func TestApply(t *testing.T) {
    t.Parallel()

    t.Run("state=present", func(t *testing.T) {
        t.Run("gid not provided", func(t *testing.T) {
Severity: Major
Found in resource/group/group_test.go - About 2 days to fix

    Function TestCheck has 322 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func TestCheck(t *testing.T) {
        t.Parallel()
    
        t.Run("state=present", func(t *testing.T) {
            g := group.NewGroup(new(group.System))
    Severity: Major
    Found in resource/group/group_test.go - About 1 day to fix

      File group_test.go has 874 lines of code (exceeds 500 allowed). Consider refactoring.
      Open

      // Copyright © 2016 Asteris, LLC
      //
      // 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
      Severity: Major
      Found in resource/group/group_test.go - About 1 day to fix

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        t.Run("no modify-will not attempt add/modify", func(t *testing.T) {
                            grp := &user.Group{
                                Name: currName,
                                Gid:  fakeGid,
                            }
        Severity: Major
        Found in resource/group/group_test.go and 1 other location - About 3 hrs to fix
        resource/group/group_test.go on lines 636..655

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 291.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        t.Run("no add-will not attempt add/modify", func(t *testing.T) {
                            grp := &user.Group{
                                Name: fakeName,
                                Gid:  fakeGid,
                            }
        Severity: Major
        Found in resource/group/group_test.go and 1 other location - About 3 hrs to fix
        resource/group/group_test.go on lines 702..721

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 291.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

                        t.Run("no add-group gid already exists", func(t *testing.T) {
                            g.GID = currGid
                            g.Name = fakeName
                            status, err := g.Check(context.Background(), fakerenderer.New())
        
        
        Severity: Major
        Found in resource/group/group_test.go and 3 other locations - About 2 hrs to fix
        resource/group/group_test.go on lines 134..147
        resource/group/group_test.go on lines 373..386
        resource/group/group_test.go on lines 388..401

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 196.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                            if runtime.GOOS == "linux" {
                                assert.NoError(t, err)
                                assert.Equal(t, resource.StatusWillChange, status.StatusCode())
                                assert.Equal(t, "modify group name and gid", status.Messages()[0])
                                assert.Equal(t, fmt.Sprintf("group %s with gid %s", g.Name, currGid), status.Diffs()["group"].Original())
        Severity: Major
        Found in resource/group/group_test.go and 1 other location - About 2 hrs to fix
        resource/group/group_test.go on lines 224..233

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 196.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

                    t.Run("no delete-group name does not exist", func(t *testing.T) {
                        g.GID = currGid
                        g.Name = fakeName
                        status, err := g.Check(context.Background(), fakerenderer.New())
        
        
        Severity: Major
        Found in resource/group/group_test.go and 3 other locations - About 2 hrs to fix
        resource/group/group_test.go on lines 134..147
        resource/group/group_test.go on lines 204..217
        resource/group/group_test.go on lines 388..401

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 196.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

                        t.Run("no modify-group does not exist", func(t *testing.T) {
                            g.Name = fakeName
                            g.NewName = fakeName
                            status, err := g.Check(context.Background(), fakerenderer.New())
        
        
        Severity: Major
        Found in resource/group/group_test.go and 3 other locations - About 2 hrs to fix
        resource/group/group_test.go on lines 204..217
        resource/group/group_test.go on lines 373..386
        resource/group/group_test.go on lines 388..401

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 196.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

                    t.Run("no delete-group gid does not exist", func(t *testing.T) {
                        g.GID = fakeGid
                        g.Name = currName
                        status, err := g.Check(context.Background(), fakerenderer.New())
        
        
        Severity: Major
        Found in resource/group/group_test.go and 3 other locations - About 2 hrs to fix
        resource/group/group_test.go on lines 134..147
        resource/group/group_test.go on lines 204..217
        resource/group/group_test.go on lines 373..386

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 196.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                            if runtime.GOOS == "linux" {
                                assert.NoError(t, err)
                                assert.Equal(t, resource.StatusWillChange, status.StatusCode())
                                assert.Equal(t, "modify group gid", status.Messages()[0])
                                assert.Equal(t, fmt.Sprintf("group %s with gid %s", g.Name, currGid), status.Diffs()["group"].Original())
        Severity: Major
        Found in resource/group/group_test.go and 1 other location - About 2 hrs to fix
        resource/group/group_test.go on lines 275..284

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 196.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                        t.Run("no add-group already exists", func(t *testing.T) {
                            g.Name = currName
                            status, err := g.Check(context.Background(), fakerenderer.New())
        
                            if runtime.GOOS == "linux" {
        Severity: Major
        Found in resource/group/group_test.go and 1 other location - About 1 hr to fix
        resource/group/group_test.go on lines 327..339

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 186.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

                    t.Run("no delete-group does not exist", func(t *testing.T) {
                        g.Name = fakeName
                        status, err := g.Check(context.Background(), fakerenderer.New())
        
                        if runtime.GOOS == "linux" {
        Severity: Major
        Found in resource/group/group_test.go and 1 other location - About 1 hr to fix
        resource/group/group_test.go on lines 102..114

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 186.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                            if runtime.GOOS == "linux" {
                                assert.EqualError(t, err, "cannot add or modify group")
                                assert.Equal(t, resource.StatusCantChange, status.StatusCode())
                                assert.Equal(t, fmt.Sprintf("group add/modify: group %s and gid %s belong to different groups", g.Name, g.GID), status.Messages()[0])
                                assert.True(t, status.HasChanges())
        Severity: Major
        Found in resource/group/group_test.go and 2 other locations - About 55 mins to fix
        resource/group/group_test.go on lines 257..264
        resource/group/group_test.go on lines 412..419

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 125.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                            if runtime.GOOS == "linux" {
                                assert.EqualError(t, err, "cannot add or modify group")
                                assert.Equal(t, resource.StatusCantChange, status.StatusCode())
                                assert.Equal(t, fmt.Sprintf("group add/modify: group %s with gid %s already exists", g.Name, g.GID), status.Messages()[0])
                                assert.True(t, status.HasChanges())
        Severity: Major
        Found in resource/group/group_test.go and 2 other locations - About 55 mins to fix
        resource/group/group_test.go on lines 241..248
        resource/group/group_test.go on lines 412..419

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 125.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

                        if runtime.GOOS == "linux" {
                            assert.EqualError(t, err, "cannot delete group")
                            assert.Equal(t, resource.StatusCantChange, status.StatusCode())
                            assert.Equal(t, fmt.Sprintf("group delete: group %s and gid %s belong to different groups", g.Name, g.GID), status.Messages()[0])
                            assert.True(t, status.HasChanges())
        Severity: Major
        Found in resource/group/group_test.go and 2 other locations - About 55 mins to fix
        resource/group/group_test.go on lines 241..248
        resource/group/group_test.go on lines 257..264

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 125.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func setGid() (string, error) {
            for i := 0; i <= maxGID; i++ {
                gid := strconv.Itoa(i)
                group, err := user.LookupGroupId(gid)
                if err == nil && group.Name != currName {
        Severity: Minor
        Found in resource/group/group_test.go and 1 other location - About 40 mins to fix
        resource/user/user_test.go on lines 1398..1407

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 109.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status