Files
Matheus Sampaio Queiroga fb6024ec5d big update and move dpkg module
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-03-13 14:40:14 -03:00

90 lines
2.2 KiB
Go

package apt
import (
"encoding/json"
"net/url"
"testing"
)
func TestParsePackages(t *testing.T) {
pkgSum := Sum{
File: "main/binary-amd64/Packages.gz",
}
pkgs, err := pkgSum.Packages("stable", &AptSource{
Suites: []string{"main", "stable"},
URIs: []*url.URL{
{
Scheme: "http",
Host: "ftp.debian.org",
Path: "/debian",
},
},
})
if err != nil {
t.Error(err)
return
}
d, _ := json.MarshalIndent(pkgs, "", " ")
t.Logf("Packages:\n%s\n\nPkgs: %d", d, len(pkgs))
}
var (
sourceDeb822 = `Types: deb deb-src
URIs: https://deb.debian.org/debian
Suites: bookworm bookworm-updates
Components: main non-free-firmware
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
Types: deb deb-src
URIs: https://security.debian.org/debian-security
Suites: bookworm-security
Components: main non-free-firmware
Enabled: yes
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg`
sourceApt = `# deb http://snapshot.debian.org/archive/debian/20240612T000000Z buster main
deb http://deb.debian.org/debian buster main
# deb http://snapshot.debian.org/archive/debian-security/20240612T000000Z buster/updates main
deb http://deb.debian.org/debian-security buster/updates main
# deb http://snapshot.debian.org/archive/debian/20240612T000000Z buster-updates main
deb http://deb.debian.org/debian buster-updates main
# deb-src [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian buster stable
deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian buster stable
`
)
func TestParseSources(t *testing.T) {
sources, err := ParseSourcelist(sourceApt)
if err != nil {
t.Error(err)
return
}
d, _ := json.MarshalIndent(sources, "", " ")
t.Logf("Sources apt:\n%s", d)
if sources, err = ParseSourcelist(sourceDeb822); err != nil {
t.Error(err)
return
}
d, _ = json.MarshalIndent(sources, "", " ")
t.Logf("Sources deb822:\n%s", d)
}
func TestRelease(t *testing.T) {
sources, err := ParseSourcelist(sourceDeb822)
if err != nil {
t.Skip(err)
return
}
rel, err := sources[0].Release()
if err != nil {
t.Error(err)
return
}
d, _ := json.MarshalIndent(rel, "", " ")
t.Log(string(d))
}