Files
go-dpkg/apt/apt_test.go
Matheus Sampaio Queiroga 8cf5fcbfc3
All checks were successful
Golang test / go-test (pull_request) Successful in 21s
Golang test / go-test (push) Successful in 21s
Refactor deb822 package: Remove deprecated files and implement new encoding/decoding logic
- Deleted old deb822_encode.go and deb822_types.go files.
- Introduced new deb822_encode.go with improved Marshall function and Writer struct for encoding.
- Added deb822_decode.go for decoding functionality with enhanced error handling.
- Created deb822_rawdata.go to define RawData type for handling raw deb822 values.
- Implemented Description type in deb822/datatype/description.go for structured description handling.
- Updated Package struct in dpkg/header.go to use new Description type.
- Refactored UnmarshalBinary method in dpkg/header.go to utilize new deb822 decoding logic.
- Added comprehensive tests for encoding and decoding in deb822_encode_test.go and deb822_decode_test.go.
- Removed internal scanner package as it was no longer needed.

Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-06-22 22:05:41 -03:00

56 lines
1.6 KiB
Go

package apt
import (
"encoding/json"
"strings"
"testing"
)
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) {
t.Run("source_list", func(t *testing.T) {
sources, err := ParseOneLine(strings.NewReader(sourceApt))
if err != nil {
t.Error(err)
return
}
d, _ := json.MarshalIndent(sources, "", " ")
t.Logf("Sources apt:\n%s", d)
})
t.Run("deb822", func(t *testing.T) {
sources, err := ParseDeb822(strings.NewReader(sourceDeb822))
if err != nil {
t.Error(err)
return
}
d, _ := json.MarshalIndent(sources, "", " ")
t.Logf("Sources deb822:\n%s", d)
})
}