aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Daudt <kdaudt@alpinelinux.org>2021-11-27 15:35:33 +0100
committerKevin Daudt <kdaudt@alpinelinux.org>2021-11-27 15:35:33 +0100
commitaaea9d44a6dbcf4a907ffbd78718c46ca5edcc9e (patch)
treed9bd70ff94ad5d0c8e04d7a5c75ffb8769c989bf
parent3416577acad5786bfe3181700276509bf14fe0cf (diff)
downloadgo-aaea9d44a6dbcf4a907ffbd78718c46ca5edcc9e.tar.gz
go-aaea9d44a6dbcf4a907ffbd78718c46ca5edcc9e.tar.bz2
go-aaea9d44a6dbcf4a907ffbd78718c46ca5edcc9e.tar.xz
repository: extract package struct to separate file
-rw-r--r--pkg/repository/apkindex.go13
-rw-r--r--pkg/repository/package.go23
-rw-r--r--pkg/repository/package_test.go16
3 files changed, 39 insertions, 13 deletions
diff --git a/pkg/repository/apkindex.go b/pkg/repository/apkindex.go
index 1809bd4..bc9c473 100644
--- a/pkg/repository/apkindex.go
+++ b/pkg/repository/apkindex.go
@@ -10,19 +10,6 @@ import (
"strings"
)
-type Package struct {
- Name string
- Version string
- Arch string
- Description string
- License string
- Origin string
- Maintainer string
- Checksum []byte
- Dependencies []string
- Provides []string
-}
-
type ApkIndex struct {
Signature []byte
Description string
diff --git a/pkg/repository/package.go b/pkg/repository/package.go
new file mode 100644
index 0000000..745aeaa
--- /dev/null
+++ b/pkg/repository/package.go
@@ -0,0 +1,23 @@
+package repository
+
+import "fmt"
+
+//Package represents a single package with the information present in an
+//APKINDEX.
+type Package struct {
+ Name string
+ Version string
+ Arch string
+ Description string
+ License string
+ Origin string
+ Maintainer string
+ Checksum []byte
+ Dependencies []string
+ Provides []string
+}
+
+//Returns the package filename as it's named in a repository.
+func (p *Package) Filename() string {
+ return fmt.Sprintf("%s-%s.apk", p.Name, p.Version)
+}
diff --git a/pkg/repository/package_test.go b/pkg/repository/package_test.go
new file mode 100644
index 0000000..0ef3f14
--- /dev/null
+++ b/pkg/repository/package_test.go
@@ -0,0 +1,16 @@
+package repository
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestPackageReturnsProperFilename(t *testing.T) {
+ pkg := Package{
+ Name: "test-package",
+ Version: "1.2.3-r0",
+ }
+
+ assert.Equal(t, "test-package-1.2.3-r0.apk", pkg.Filename())
+}