mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: consolidate Go tests (#39962)
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
This commit is contained in:
1 parent
ce7364e215
commit
8abda62312
388 files changed
+18410
-29561
No files matched your search
@@ -37,8 +37,11 @@ func createDescription(name, version string) *bytes.Buffer {
|
||||
}
|
||||
|
||||
func TestParsePackage(t *testing.T) {
|
||||
t.Run(".tar.gz", func(t *testing.T) {
|
||||
createArchive := func(filename string, content []byte) *bytes.Reader {
|
||||
for _, archive := range []struct {
|
||||
extension string
|
||||
create func(string, []byte) *bytes.Reader
|
||||
}{
|
||||
{".tar.gz", func(filename string, content []byte) *bytes.Reader {
|
||||
var buf bytes.Buffer
|
||||
gw := gzip.NewWriter(&buf)
|
||||
tw := tar.NewWriter(gw)
|
||||
@@ -52,70 +55,43 @@ func TestParsePackage(t *testing.T) {
|
||||
tw.Close()
|
||||
gw.Close()
|
||||
return bytes.NewReader(buf.Bytes())
|
||||
}
|
||||
|
||||
t.Run("MissingDescriptionFile", func(t *testing.T) {
|
||||
buf := createArchive(
|
||||
"dummy.txt",
|
||||
[]byte{},
|
||||
)
|
||||
|
||||
p, err := ParsePackage(buf, buf.Size())
|
||||
assert.Nil(t, p)
|
||||
assert.ErrorIs(t, err, ErrMissingDescriptionFile)
|
||||
})
|
||||
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
buf := createArchive(
|
||||
"package/DESCRIPTION",
|
||||
createDescription(packageName, packageVersion).Bytes(),
|
||||
)
|
||||
|
||||
p, err := ParsePackage(buf, buf.Size())
|
||||
|
||||
assert.NotNil(t, p)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, packageName, p.Name)
|
||||
assert.Equal(t, packageVersion, p.Version)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run(".zip", func(t *testing.T) {
|
||||
createArchive := func(filename string, content []byte) *bytes.Reader {
|
||||
}},
|
||||
{".zip", func(filename string, content []byte) *bytes.Reader {
|
||||
var buf bytes.Buffer
|
||||
archive := zip.NewWriter(&buf)
|
||||
w, _ := archive.Create(filename)
|
||||
w.Write(content)
|
||||
archive.Close()
|
||||
return bytes.NewReader(buf.Bytes())
|
||||
}
|
||||
}},
|
||||
} {
|
||||
t.Run(archive.extension, func(t *testing.T) {
|
||||
t.Run("MissingDescriptionFile", func(t *testing.T) {
|
||||
buf := archive.create(
|
||||
"dummy.txt",
|
||||
[]byte{},
|
||||
)
|
||||
|
||||
t.Run("MissingDescriptionFile", func(t *testing.T) {
|
||||
buf := createArchive(
|
||||
"dummy.txt",
|
||||
[]byte{},
|
||||
)
|
||||
p, err := ParsePackage(buf, buf.Size())
|
||||
assert.Nil(t, p)
|
||||
assert.ErrorIs(t, err, ErrMissingDescriptionFile)
|
||||
})
|
||||
|
||||
p, err := ParsePackage(buf, buf.Size())
|
||||
assert.Nil(t, p)
|
||||
assert.ErrorIs(t, err, ErrMissingDescriptionFile)
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
buf := archive.create(
|
||||
"package/DESCRIPTION",
|
||||
createDescription(packageName, packageVersion).Bytes(),
|
||||
)
|
||||
|
||||
p, err := ParsePackage(buf, buf.Size())
|
||||
assert.NotNil(t, p)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, packageName, p.Name)
|
||||
assert.Equal(t, packageVersion, p.Version)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
buf := createArchive(
|
||||
"package/DESCRIPTION",
|
||||
createDescription(packageName, packageVersion).Bytes(),
|
||||
)
|
||||
|
||||
p, err := ParsePackage(buf, buf.Size())
|
||||
assert.NotNil(t, p)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, packageName, p.Name)
|
||||
assert.Equal(t, packageVersion, p.Version)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDescription(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user