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.

blob_test.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2019 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 repofiles
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/test"
  9. api "code.gitea.io/sdk/gitea"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestGetBlobBySHA(t *testing.T) {
  13. models.PrepareTestEnv(t)
  14. ctx := test.MockContext(t, "user2/repo1")
  15. test.LoadRepo(t, ctx, 1)
  16. test.LoadRepoCommit(t, ctx)
  17. test.LoadUser(t, ctx, 2)
  18. test.LoadGitRepo(t, ctx)
  19. sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
  20. ctx.SetParams(":id", "1")
  21. ctx.SetParams(":sha", sha)
  22. gbr, err := GetBlobBySHA(ctx.Repo.Repository, ctx.Params(":sha"))
  23. expectedGBR := &api.GitBlobResponse{
  24. Content: "dHJlZSAyYTJmMWQ0NjcwNzI4YTJlMTAwNDllMzQ1YmQ3YTI3NjQ2OGJlYWI2CmF1dGhvciB1c2VyMSA8YWRkcmVzczFAZXhhbXBsZS5jb20+IDE0ODk5NTY0NzkgLTA0MDAKY29tbWl0dGVyIEV0aGFuIEtvZW5pZyA8ZXRoYW50a29lbmlnQGdtYWlsLmNvbT4gMTQ4OTk1NjQ3OSAtMDQwMAoKSW5pdGlhbCBjb21taXQK",
  25. Encoding: "base64",
  26. URL: "https://try.gitea.io/api/v1/repos/user2/repo1/git/blobs/65f1bf27bc3bf70f64657658635e66094edbcb4d",
  27. SHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
  28. Size: 180,
  29. }
  30. assert.Nil(t, err)
  31. assert.Equal(t, expectedGBR, gbr)
  32. }