Skip to content

Commit

Permalink
Fix clilog file name
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <[email protected]>
  • Loading branch information
saswatamcode committed May 19, 2021
1 parent c09ec55 commit 78ce34e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
13 changes: 11 additions & 2 deletions pkg/mdformatter/linktransformer/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,23 @@ func (v *validator) Close(ctx mdformatter.SourceContext) error {
})

merr := merrors.New()
base, err := os.Getwd()
if err != nil {
merr.Add(errors.Wrapf(err, "could not resolve working dir"))
}
path, err := filepath.Rel(base, ctx.Filepath)
if err != nil {
merr.Add(errors.Wrapf(err, "could not find relative path"))
}

for _, k := range keys {
f := v.destFutures[k]
if err := f.resultFn(); err != nil {
if f.cases == 1 {
merr.Add(err)
merr.Add(errors.Wrapf(err, "%v", path))
continue
}
merr.Add(errors.Wrapf(err, "(%v occurrences)", f.cases))
merr.Add(errors.Wrapf(err, "%v (%v occurrences)", path, f.cases))
}
}
return merr.Err()
Expand Down
18 changes: 11 additions & 7 deletions pkg/mdformatter/linktransformer/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func TestValidator_TransformDestination(t *testing.T) {

t.Run("check invalid local links", func(t *testing.T) {
testFile := filepath.Join(tmpDir, "repo", "docs", "test", "invalid-local-links.md")
rel := "../../../../../../.."
tmpDirPath := tmpDir + "/repo/docs/test/invalid-local-links.md"
testutil.Ok(t, ioutil.WriteFile(testFile, []byte(`# yolo
[1](.) [2](#not-yolo) [3](../test2/invalid-local-links.md) [4](../test/invalid-local-links.md#not-yolo) [5](../test/doc.md)
Expand All @@ -196,17 +198,19 @@ func TestValidator_TransformDestination(t *testing.T) {
MustNewValidator(logger, regexp.MustCompile(`^$`), anchorDir),
))
testutil.NotOk(t, err)
testutil.Equals(t, fmt.Sprintf("%v/repo/docs/test/invalid-local-links.md: 4 errors: "+
"link ../test2/invalid-local-links.md, normalized to: %v/repo/docs/test2/invalid-local-links.md: file not found; "+
"link ../test/invalid-local-links.md#not-yolo, normalized to: link %v/repo/docs/test/invalid-local-links.md#not-yolo, existing ids: [yolo]: file exists, but does not have such id; "+
"link ../test/doc.md, normalized to: %v/repo/docs/test/doc.md: file not found; "+
"link #not-yolo, normalized to: link %v/repo/docs/test/invalid-local-links.md#not-yolo, existing ids: [yolo]: file exists, but does not have such id",
tmpDir, tmpDir, tmpDir, tmpDir, tmpDir), err.Error())

testutil.Equals(t, fmt.Sprintf("%v: 4 errors: "+
"%v: link ../test2/invalid-local-links.md, normalized to: %v/repo/docs/test2/invalid-local-links.md: file not found; "+
"%v: link ../test/invalid-local-links.md#not-yolo, normalized to: link %v/repo/docs/test/invalid-local-links.md#not-yolo, existing ids: [yolo]: file exists, but does not have such id; "+
"%v: link ../test/doc.md, normalized to: %v/repo/docs/test/doc.md: file not found; "+
"%v: link #not-yolo, normalized to: link %v/repo/docs/test/invalid-local-links.md#not-yolo, existing ids: [yolo]: file exists, but does not have such id",
tmpDirPath, rel+tmpDirPath, tmpDir, rel+tmpDirPath, tmpDir, rel+tmpDirPath, tmpDir, rel+tmpDirPath, tmpDir), err.Error())
})

t.Run("check 404 link", func(t *testing.T) {
testFile := filepath.Join(tmpDir, "repo", "docs", "test", "invalid-link.md")
testutil.Ok(t, ioutil.WriteFile(testFile, []byte("https://bwplotka.dev/does-not-exists\n"), os.ModePerm))
tmpDirPath := tmpDir + "/repo/docs/test/invalid-link.md"

diff, err := mdformatter.IsFormatted(context.TODO(), logger, []string{testFile})
testutil.Ok(t, err)
Expand All @@ -216,7 +220,7 @@ func TestValidator_TransformDestination(t *testing.T) {
MustNewValidator(logger, regexp.MustCompile(`^$`), anchorDir),
))
testutil.NotOk(t, err)
testutil.Equals(t, tmpDir+"/repo/docs/test/invalid-link.md: \"https://bwplotka.dev/does-not-exists\" not accessible; status code 404: Not Found", err.Error())
testutil.Equals(t, fmt.Sprintf("%v: ../../../../../../..%v: \"https://bwplotka.dev/does-not-exists\" not accessible; status code 404: Not Found", tmpDirPath, tmpDirPath), err.Error())
})

t.Run("check 404 link, ignored", func(t *testing.T) {
Expand Down

0 comments on commit 78ce34e

Please sign in to comment.