Skip to content

Failed to sort by dependency #332

Description

@tennashi

The following test for the sortByDepends() function fails.

package plugconf                                                                                                                 |
                                                                                                                                 |
import (                                                                                                                         |
  "reflect"                                                                                                                      |
  "testing"                                                                                                                      |
                                                                                                                                 |
  "github.com/vim-volt/volt/lockjson"                                                                                            |
  "github.com/vim-volt/volt/pathutil"                                                                                            |
)                                                                                                                                |
                                                                                                                                 |
func TestSortByDepends(t *testing.T) {                                                                                           |
  reposList := []lockjson.Repos{                                                                                                 |
    {Path: pathutil.DecodeReposPath("test/test-1")},                                                                             |
    {Path: pathutil.DecodeReposPath("test/test-2")},                                                                             |
    {Path: pathutil.DecodeReposPath("test/test-3")},                                                                             |
  }                                                                                                                              |
                                                                                                                                 |
  plugconfMap := map[pathutil.ReposPath]*ParsedInfo{                                                                             |
    pathutil.DecodeReposPath("test/test-1"): {                                                                                   |
      depends: []pathutil.ReposPath{                                                                                             |
        pathutil.DecodeReposPath("test/test-2"),                                                                                 |
      },                                                                                                                         |
    },                                                                                                                           |
    pathutil.DecodeReposPath("test/test-2"): {                                                                                   |
      depends: []pathutil.ReposPath{                                                                                             |
        pathutil.DecodeReposPath("test/test-3"),                                                                                 |
      },                                                                                                                         |
    },                                                                                                                           |
    pathutil.DecodeReposPath("test/test-3"): {},                                                                                 |
  }                                                                                                                              |
                                                                                                                                 |
  sortByDepends(reposList, plugconfMap)
                                                                                                                                 |
  want := []lockjson.Repos{                                                                                                      |
    {Path: pathutil.DecodeReposPath("test/test-3")},                                                                             |
    {Path: pathutil.DecodeReposPath("test/test-2")},                                                                             |
    {Path: pathutil.DecodeReposPath("test/test-1")},                                                                             |
  }                                                                                                                              |
                                                                                                                                 |
  if !reflect.DeepEqual(reposList, want) {                                                                                       |
    t.Fatalf("want: %v, but got: %v", want, reposList)                                                                           |
  }                                                                                                                              |
}

The following is the result:

=== RUN   TestSortByDepends
    plugconf_test.go:41: want: [{ test-3 } { test-2 } { test-1 }], but got: [{ test-1 } { test-3 } { test-2 }]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions