-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
687 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package dvcore | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/cayleygraph/cayley/graph" | ||
"github.com/cayleygraph/quad" | ||
"github.com/stretchr/testify/assert" | ||
"moul.io/depviz/internal/dvstore" | ||
"moul.io/depviz/internal/testutil" | ||
"moul.io/multipmuri" | ||
) | ||
|
||
func TestPullAndSave(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping slow test (--short)") | ||
} | ||
githubToken := os.Getenv("GITHUB_TOKEN") | ||
if githubToken == "" { | ||
t.Skip("missing GITHUB_TOKEN") | ||
} | ||
schema := dvstore.Schema() | ||
gitlabToken := "" | ||
logger := testutil.Logger(t) | ||
|
||
tests := []struct { | ||
name string | ||
targets []multipmuri.Entity | ||
}{ | ||
{ | ||
"moul-depviz-test", | ||
[]multipmuri.Entity{ | ||
multipmuri.NewGitHubRepo("github.com", "moul", "depviz-test"), | ||
}, | ||
}, | ||
{ | ||
"moulbot-depviz-test", | ||
[]multipmuri.Entity{ | ||
multipmuri.NewGitHubRepo("github.com", "moul-bot", "depviz-test"), | ||
}, | ||
}, | ||
{ | ||
"all-depviz-test", | ||
[]multipmuri.Entity{ | ||
multipmuri.NewGitHubRepo("github.com", "moul", "depviz-test"), | ||
multipmuri.NewGitHubRepo("github.com", "moul-bot", "depviz-test"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
store, close := dvstore.TestingStore(t) | ||
defer close() | ||
changed, err := PullAndSave(test.targets, store, schema, githubToken, gitlabToken, false, logger) | ||
assert.NoError(t, err, test.name) | ||
assert.True(t, changed, test.name) | ||
changed, err = PullAndSave(test.targets, store, schema, githubToken, gitlabToken, false, logger) | ||
assert.NoError(t, err, test.name) | ||
assert.False(t, changed, test.name) | ||
changed, err = PullAndSave(test.targets, store, schema, githubToken, gitlabToken, true, logger) | ||
assert.NoError(t, err, test.name) | ||
assert.True(t, changed, test.name) | ||
|
||
var b bytes.Buffer | ||
qr := graph.NewQuadStoreReader(store.QuadStore) | ||
assert.NotNil(t, qr, test.name) | ||
defer qr.Close() | ||
|
||
format := quad.FormatByName(dvstore.GoldenFormat) | ||
assert.NotNil(t, format, test.name) | ||
|
||
qw := format.Writer(&b) | ||
assert.NotNil(t, qw, test.name) | ||
defer qw.Close() | ||
|
||
n, err := quad.Copy(qw, qr) | ||
assert.Greater(t, n, 0, test.name) | ||
assert.NoError(t, err, test.name) | ||
|
||
gp := dvstore.TestingGoldenDumpPath(t, test.name) | ||
if testutil.UpdateGolden() { | ||
t.Logf("update golden file: %s", gp) | ||
err := ioutil.WriteFile(gp, b.Bytes(), 0644) | ||
assert.NoError(t, err, test.name) | ||
} | ||
|
||
g, err := ioutil.ReadFile(gp) | ||
assert.NoError(t, err, test.name) | ||
assert.Equal(t, string(g), b.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dvstore | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
"testing" | ||
|
||
_ "github.com/cayleygraph/quad/json" | ||
"github.com/stretchr/testify/assert" | ||
"moul.io/depviz/internal/dvparser" | ||
"moul.io/depviz/internal/testutil" | ||
"moul.io/godev" | ||
"moul.io/multipmuri" | ||
) | ||
|
||
func TestLoadTasks(t *testing.T) { | ||
tests := []struct { | ||
golden string | ||
name string | ||
filters LoadTasksFilters | ||
expectedErr error | ||
}{ | ||
{"all-depviz-test", "theworld", LoadTasksFilters{TheWorld: true}, nil}, | ||
{"all-depviz-test", "theworld-light", LoadTasksFilters{TheWorld: true, WithoutPRs: true, WithClosed: false, WithoutExternalDeps: true}, nil}, | ||
{"all-depviz-test", "theworld-with-closed", LoadTasksFilters{TheWorld: true, WithClosed: true}, nil}, | ||
{"all-depviz-test", "theworld-without-prs", LoadTasksFilters{TheWorld: true, WithoutPRs: true}, nil}, | ||
{"all-depviz-test", "theworld-without-isolated", LoadTasksFilters{TheWorld: true, WithoutIsolated: true}, nil}, | ||
{"all-depviz-test", "theworld-without-external-deps", LoadTasksFilters{TheWorld: true, WithoutExternalDeps: true}, nil}, | ||
{"all-depviz-test", "theworld-all-flags", LoadTasksFilters{TheWorld: true, WithClosed: true, WithoutPRs: true, WithoutIsolated: true, WithoutExternalDeps: true}, nil}, | ||
{"all-depviz-test", "moul-depviz-test", LoadTasksFilters{Targets: parseTargets(t, "moul/depviz-test")}, nil}, | ||
{"all-depviz-test", "moulbot-depviz-test", LoadTasksFilters{Targets: parseTargets(t, "moul-bot/depviz-test")}, nil}, | ||
{"all-depviz-test", "moul-and-moulbot-depviz-test", LoadTasksFilters{Targets: parseTargets(t, "moul/depviz-test, moul-bot/depviz-test")}, nil}, | ||
} | ||
alreadySeen := map[string]bool{} | ||
for _, test := range tests { | ||
name := fmt.Sprintf("%s/%s", test.golden, test.name) | ||
gp := TestingGoldenJSONPath(t, name) | ||
if _, found := alreadySeen[gp]; found { | ||
t.Fatalf("duplicate key: %q (golden files conflict)", gp) | ||
} | ||
alreadySeen[gp] = true | ||
|
||
t.Run(name, func(t *testing.T) { | ||
logger := testutil.Logger(t) | ||
store, close := TestingGoldenStore(t, test.golden) | ||
defer close() | ||
tasks, err := LoadTasks(store, schemaConfig, test.filters, logger) | ||
assert.Equal(t, test.expectedErr, err) | ||
if err != nil { | ||
return | ||
} | ||
assert.NotNil(t, tasks) | ||
assert.NoError(t, err) | ||
|
||
actual := godev.JSON(test.filters) + "\n" | ||
for _, task := range tasks { | ||
actual += godev.JSON(task) + "\n" | ||
} | ||
|
||
if testutil.UpdateGolden() { | ||
t.Logf("update golden file: %s", gp) | ||
err := ioutil.WriteFile(gp, []byte(actual), 0644) | ||
assert.NoError(t, err, name) | ||
} | ||
|
||
g, err := ioutil.ReadFile(gp) | ||
assert.NoError(t, err, name) | ||
assert.Equal(t, len(string(g)), len(actual), gp) | ||
}) | ||
} | ||
} | ||
|
||
func parseTargets(t *testing.T, input string) []multipmuri.Entity { | ||
t.Helper() | ||
targets, err := dvparser.ParseTargets(strings.Split(input, ", ")) | ||
if !assert.NoError(t, err) { | ||
t.Fatalf("parse targets: %v", input) | ||
} | ||
return targets | ||
} |
Empty file.
Binary file not shown.
Oops, something went wrong.