You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
853 B

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "io/ioutil"
  7. "os"
  8. "path/filepath"
  9. "testing"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestGetFormatPatch(t *testing.T) {
  13. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  14. clonedPath, err := cloneRepo(bareRepo1Path, testReposDir, "repo1_TestGetFormatPatch")
  15. assert.NoError(t, err)
  16. defer os.RemoveAll(clonedPath)
  17. repo, err := OpenRepository(clonedPath)
  18. assert.NoError(t, err)
  19. rd, err := repo.GetFormatPatch("8d92fc95^", "8d92fc95")
  20. assert.NoError(t, err)
  21. patchb, err := ioutil.ReadAll(rd)
  22. assert.NoError(t, err)
  23. patch := string(patchb)
  24. assert.Regexp(t, "^From 8d92fc95", patch)
  25. assert.Contains(t, patch, "Subject: [PATCH] Add file2.txt")
  26. }