Fix issues with Repository synchronization tool (#124)
* Only run tests in build/sync if directory exists * Use t.Helper() * Don't compare size of directories * Fix TestFileHistory * Fix linter issue * Apply changes from https://github.com/mattermost/mattermost-plugin-github/pull/345 * Use ts file for tests * Add sync target
This commit is contained in:
parent
0688e8df4c
commit
dcaf9dd289
11 changed files with 776 additions and 12 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -122,6 +123,7 @@ func applyManifest(manifest *model.Manifest) error {
|
|||
return err
|
||||
}
|
||||
manifestStr := string(manifestBytes)
|
||||
manifestStr = strings.ReplaceAll(manifestStr, "\\n", "\\\n")
|
||||
|
||||
// write generated code to file by using Go file template.
|
||||
if err := ioutil.WriteFile(
|
||||
|
@ -145,7 +147,7 @@ func applyManifest(manifest *model.Manifest) error {
|
|||
|
||||
// write generated code to file by using JS file template.
|
||||
if err := ioutil.WriteFile(
|
||||
"webapp/src/manifest.js",
|
||||
"webapp/src/manifest.ts",
|
||||
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifestStr)),
|
||||
0600,
|
||||
); err != nil {
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestCopyDirectory(t *testing.T) {
|
|||
err = plan.CopyDirectory(srcDir, dir)
|
||||
assert.Nil(err)
|
||||
|
||||
compareDirectories(assert, dir, srcDir)
|
||||
compareDirectories(t, dir, srcDir)
|
||||
}
|
||||
|
||||
func TestOverwriteFileAction(t *testing.T) {
|
||||
|
@ -55,7 +55,7 @@ func TestOverwriteFileAction(t *testing.T) {
|
|||
err = action.Run("c", setup)
|
||||
assert.Nil(err)
|
||||
|
||||
compareDirectories(assert, dir, filepath.Join(wd, "testdata", "b"))
|
||||
compareDirectories(t, dir, filepath.Join(wd, "testdata", "b"))
|
||||
}
|
||||
|
||||
func TestOverwriteDirectoryAction(t *testing.T) {
|
||||
|
@ -86,10 +86,13 @@ func TestOverwriteDirectoryAction(t *testing.T) {
|
|||
|
||||
destDir := filepath.Join(dir, "testdata")
|
||||
srcDir := filepath.Join(wd, "testdata")
|
||||
compareDirectories(assert, destDir, srcDir)
|
||||
compareDirectories(t, destDir, srcDir)
|
||||
}
|
||||
|
||||
func compareDirectories(assert *assert.Assertions, pathA, pathB string) {
|
||||
func compareDirectories(t *testing.T, pathA, pathB string) {
|
||||
assert := assert.New(t)
|
||||
t.Helper()
|
||||
|
||||
aContents, err := ioutil.ReadDir(pathA)
|
||||
assert.Nil(err)
|
||||
bContents, err := ioutil.ReadDir(pathB)
|
||||
|
@ -100,8 +103,10 @@ func compareDirectories(assert *assert.Assertions, pathA, pathB string) {
|
|||
for i, aFInfo := range aContents {
|
||||
bFInfo := bContents[i]
|
||||
assert.Equal(aFInfo.Name(), bFInfo.Name())
|
||||
assert.Equal(aFInfo.Size(), bFInfo.Size())
|
||||
assert.Equal(aFInfo.Mode(), bFInfo.Mode())
|
||||
assert.Equal(aFInfo.IsDir(), bFInfo.IsDir())
|
||||
if !aFInfo.IsDir() {
|
||||
assert.Equal(aFInfo.Size(), bFInfo.Size())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func TestRepoIsCleanChecker(t *testing.T) {
|
|||
assert.Nil(checker.Check("", ctx))
|
||||
|
||||
// Create a file in the repository.
|
||||
err = ioutil.WriteFile(path.Join(dir, "data.txt"), []byte("lorem ipsum"), 0666)
|
||||
err = ioutil.WriteFile(path.Join(dir, "data.txt"), []byte("lorem ipsum"), 0600)
|
||||
assert.Nil(err)
|
||||
err = checker.Check("", ctx)
|
||||
assert.EqualError(err, "\"target\" repository is not clean")
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestFileHistory(t *testing.T) {
|
|||
assert.Nil(err)
|
||||
sums, err := gitutil.FileHistory("build/sync/plan/git/testdata/testfile.txt", repo)
|
||||
assert.Nil(err)
|
||||
assert.Equal([]string{"ba7192052d7cf77c55d3b7bf40b350b8431b208b"}, sums)
|
||||
assert.Contains(sums, "ba7192052d7cf77c55d3b7bf40b350b8431b208b")
|
||||
|
||||
// Calling with a non-existent file returns error.
|
||||
sums, err = gitutil.FileHistory("build/sync/plan/git/testdata/nosuch_testfile.txt", repo)
|
||||
|
|
Reference in a new issue