Skip to content

Commit

Permalink
test(scope-issue): verify every output of scope issue are related to …
Browse files Browse the repository at this point in the history
…the target one
  • Loading branch information
Doozers committed Jun 2, 2023
1 parent ea3220f commit 956600c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 49 deletions.
15 changes: 8 additions & 7 deletions cmd/depviz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"os/signal"
"time"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt"
"github.com/cayleygraph/cayley/schema"
"github.com/oklog/run"
"github.com/peterbourgon/ff/v3/ffcli"
"go.uber.org/zap"
"moul.io/banner"
"moul.io/depviz/v3/pkg/dvcore"
Expand All @@ -20,13 +26,6 @@ import (
"moul.io/srand"
"moul.io/u"
"moul.io/zapconfig"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt"
"github.com/cayleygraph/cayley/schema"
"github.com/oklog/run"
"github.com/peterbourgon/ff/v3/ffcli"
)

var (
Expand Down Expand Up @@ -436,6 +435,8 @@ func execGenCSV(ctx context.Context, args []string) error {
HideIsolated: *genHideIsolated,
HidePRs: *genHidePRs,
HideExternalDeps: *genHideExternalDeps,
Scope: *genScope,
ScopeSize: *genScopeSize,
Format: "csv",
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions pkg/dvcore/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"sync"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/cayley/schema"
"go.uber.org/zap"
yaml "gopkg.in/yaml.v2"
"moul.io/depviz/v3/pkg/dvmodel"
Expand All @@ -16,10 +19,6 @@ import (
"moul.io/depviz/v3/pkg/multipmuri"
"moul.io/godev"
"moul.io/graphman"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
"github.com/cayleygraph/cayley/schema"
)

type GenOpts struct {
Expand Down Expand Up @@ -57,7 +56,7 @@ func Gen(h *cayley.Handle, args []string, opts GenOpts) error {
if opts.Scope != "" {
scope, err = dvparser.ParseTarget(opts.Scope)
if err != nil {
return fmt.Errorf("parse scope: %w", err)
return fmt.Errorf("load tasks: %w", err)
}
}

Expand Down
7 changes: 3 additions & 4 deletions pkg/dvstore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"sort"
"time"

"go.uber.org/zap"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/depviz/v3/pkg/multipmuri"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph/path"
"github.com/cayleygraph/cayley/schema"
"github.com/cayleygraph/quad"
"go.uber.org/zap"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/depviz/v3/pkg/multipmuri"
)

func LastUpdatedIssueInRepo(ctx context.Context, h *cayley.Handle, entity multipmuri.Entity) (time.Time, error) { // nolint:interfacer
Expand Down
4 changes: 2 additions & 2 deletions pkg/dvstore/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"strings"
"testing"

_ "github.com/cayleygraph/quad/json"
"github.com/stretchr/testify/assert"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/depviz/v3/pkg/multipmuri"
"moul.io/depviz/v3/pkg/testutil"
"moul.io/godev"

"github.com/stretchr/testify/assert"
)

func TestLoadTasks(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/dvstore/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"github.com/cayleygraph/quad"
)

func generateCombinationsWithRepetition[T interface{}](n int, elements []T, currentCombination []T, combinations *[][]T) {
func genCombWithRep[T interface{}](n int, elements []T, currentCombination []T, combinations *[][]T) {
if n == 0 {
*combinations = append(*combinations, append([]T(nil), currentCombination...))
} else {
for _, element := range elements {
currentCombination = append(currentCombination, element)
generateCombinationsWithRepetition(n-1, elements, currentCombination, combinations)
genCombWithRep(n-1, elements, currentCombination, combinations)
currentCombination = currentCombination[:len(currentCombination)-1]
}
}
Expand All @@ -30,7 +30,7 @@ func scopeIssue(p *path.Path, scopeSize int, possibilities []quad.IRI) *path.Pat
}
var perms [][]quad.IRI
var currentPerms []quad.IRI
generateCombinationsWithRepetition(scopeSize, possibilities, currentPerms, &perms)
genCombWithRep(scopeSize, possibilities, currentPerms, &perms)

for _, perm := range perms {
p = p.Or(fold(p, perm, func(_path *path.Path, _link quad.IRI) *path.Path { return _path.Both(_link) }))
Expand Down
69 changes: 48 additions & 21 deletions pkg/dvstore/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package dvstore
import (
"testing"

"moul.io/depviz/v3/pkg/dvparser"

"github.com/stretchr/testify/assert"
"github.com/Doozers/gl/pkg/funct"
"github.com/cayleygraph/quad"
"golang.org/x/exp/slices"

"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/depviz/v3/pkg/testutil"
)

type recFunc func(task dvmodel.Task, remaining uint8, target string) bool

func TestScopeIssue(t *testing.T) {

tests := []struct {
target string
golden string
name string
filters dvmodel.Filters
expectedDependency []string
target string
golden string
name string
filters dvmodel.Filters
}{

{
"https://github.com/moul/depviz-test/issues/6",
"all-depviz-test",
Expand All @@ -36,21 +35,14 @@ func TestScopeIssue(t *testing.T) {
WithFetch: false,
ScopeSize: 1,
},
[]string{
"<https://github.com/moul/depviz-test/issues/2>",
"<https://github.com/moul/depviz-test/issues/3>",
"<https://github.com/moul/depviz-test/issues/5>",
"<https://github.com/moul/depviz-test/issues/6>",
"<https://github.com/moul/depviz-test/issues/7>",
"<https://github.com/moul/depviz-test/issues/10>",
}},
},
}

logger := testutil.Logger(t)
for _, testptr := range tests {
test := testptr
store, close := TestingGoldenStore(t, test.golden)
defer close()
store, closeFunc := TestingGoldenStore(t, test.golden)
defer closeFunc()
targetEntity, err := dvparser.ParseTarget(test.target)
if err != nil {
t.Fatal(err)
Expand All @@ -63,8 +55,43 @@ func TestScopeIssue(t *testing.T) {
return
}

mtasks := map[string]dvmodel.Task{}
for _, task := range tasks {
mtasks[task.ID.String()] = task
}

var rec recFunc
rec = func(_task dvmodel.Task, _remaining uint8, _target string) bool {
if _task.ID.String() == _target {
return true
}

if _remaining == 0 {
return false
}

if slices.Contains(funct.Map(_task.IsDependingOn, func(t quad.IRI) string {
return t.String()
}), _target) {
return true
}
for _, dep := range _task.IsDependingOn {
if t, ok := mtasks[dep.String()]; ok {
if rec(t, _remaining-1, _target) {
return true
}
}
}
return false
}

for _, task := range tasks {
assert.Equal(t, true, slices.Contains(test.expectedDependency, task.ID.String()), "unexpected dependency %q", task.ID.String())
rec1 := rec(task, uint8(test.filters.ScopeSize), "<"+test.target+">")
rec2 := rec(mtasks["<"+test.target+">"], uint8(test.filters.ScopeSize), task.ID.String())

if rec1 == false && rec2 == false {
t.Errorf("task %s should be in the scope of %s", task.ID.String(), test.target)
}
}
}
}

0 comments on commit 956600c

Please sign in to comment.