Skip to content

Commit 965c5a7

Browse files
More touchups
1 parent 7d27bad commit 965c5a7

File tree

4 files changed

+80
-22
lines changed

4 files changed

+80
-22
lines changed

pkg/apk/apk/installed_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ func TestUpdateTriggers(t *testing.T) {
434434
}
435435
triggers := "/bin /usr/bin /foo /bar/*"
436436

437-
require.NoError(t, err, "unable to create tarfs: %v", err)
438437
err = a.updateTriggers(pkg, []string{triggers})
439438
require.NoError(t, err, "unable to update triggers: %v", err)
440439

pkg/apk/expandapk/expandapk_test.go

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2026 Chainguard, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package expandapk
216

317
import (
@@ -12,14 +26,7 @@ import (
1226
)
1327

1428
func TestPkgInfo(t *testing.T) {
15-
tests := []struct {
16-
name string
17-
content string
18-
want *types.PackageInfo
19-
}{{
20-
// See example at https://wiki.alpinelinux.org/wiki/Apk_spec
21-
name: "example",
22-
content: `
29+
samplePackageInfo := `
2330
# Generated by abuild 3.9.0-r2
2431
# using fakeroot version 1.25.3
2532
# Wed Jul 6 19:09:49 UTC 2022
@@ -44,7 +51,19 @@ provides = cmd:busybox=1.35.0-r18
4451
provides = cmd:sh=1.35.0-r18
4552
depend = so:libc.musl-x86_64.so.1
4653
datahash = 7d3351ac6c3ebaf18182efb5390061f50d077ce5ade60a15909d91278f70ada7
47-
`,
54+
`
55+
56+
tests := []struct {
57+
name string
58+
files map[string]string
59+
want *types.PackageInfo
60+
wantErr bool
61+
}{{
62+
// See example at https://wiki.alpinelinux.org/wiki/Apk_spec
63+
name: "example",
64+
files: map[string]string{
65+
".PKGINFO": samplePackageInfo,
66+
},
4867
want: &types.PackageInfo{
4968
Name: "busybox",
5069
Version: "1.35.0-r18",
@@ -65,20 +84,31 @@ datahash = 7d3351ac6c3ebaf18182efb5390061f50d077ce5ade60a15909d91278f70ada7
6584
DataHash: "7d3351ac6c3ebaf18182efb5390061f50d077ce5ade60a15909d91278f70ada7",
6685
Triggers: []string{"/bin /usr/bin /sbin /usr/sbin /lib/modules/*"},
6786
},
87+
}, {
88+
name: "empty",
89+
files: map[string]string{
90+
".PKGINFO": "",
91+
},
92+
want: &types.PackageInfo{},
93+
}, {
94+
name: "no PKGINFO",
95+
wantErr: true,
6896
}}
6997

7098
for _, tt := range tests {
7199
t.Run(tt.name, func(t *testing.T) {
72100
var buf bytes.Buffer
73101
tw := tar.NewWriter(&buf)
74-
err := tw.WriteHeader(&tar.Header{
75-
Name: ".PKGINFO",
76-
Mode: 0o644,
77-
Size: int64(len([]byte(tt.content))),
78-
})
79-
require.NoError(t, err)
80-
_, err = tw.Write([]byte(tt.content))
81-
require.NoError(t, err)
102+
for name, content := range tt.files {
103+
err := tw.WriteHeader(&tar.Header{
104+
Name: name,
105+
Mode: 0o644,
106+
Size: int64(len(content)),
107+
})
108+
require.NoError(t, err)
109+
_, err = tw.Write([]byte(content))
110+
require.NoError(t, err)
111+
}
82112
require.NoError(t, tw.Close())
83113

84114
controlFs, err := tarfs.New(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
@@ -87,6 +117,10 @@ datahash = 7d3351ac6c3ebaf18182efb5390061f50d077ce5ade60a15909d91278f70ada7
87117
exp := &APKExpanded{ControlFS: controlFs}
88118

89119
got, err := exp.PkgInfo()
120+
if tt.wantErr {
121+
require.Error(t, err)
122+
return
123+
}
90124
require.NoError(t, err)
91125
require.Equal(t, tt.want, got)
92126
})

pkg/apk/types/package.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2026 Chainguard, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package types
216

317
import (
@@ -51,7 +65,6 @@ func (pkginfo *PackageInfo) AsPackage(controlHash []byte, size uint64) *Package
5165
RepoCommit: pkginfo.RepoCommit,
5266
Replaces: pkginfo.Replaces,
5367
DataHash: pkginfo.DataHash,
54-
Triggers: pkginfo.Triggers,
5568

5669
BuildTime: time.Unix(pkginfo.BuildDate, 0).UTC(),
5770
Checksum: controlHash,
@@ -82,7 +95,6 @@ type Package struct {
8295
RepoCommit string `ini:"commit"`
8396
Replaces []string `ini:"replaces,,allowshadow"`
8497
DataHash string `ini:"datahash"`
85-
Triggers []string `ini:"triggers,,allowshadow"`
8698
}
8799

88100
func (p *Package) String() string {
@@ -109,7 +121,7 @@ func ParsePackageInfo(info io.Reader) (*PackageInfo, error) {
109121
return nil, fmt.Errorf("ini.ShadowLoad(): %w", err)
110122
}
111123

112-
pkg := new(PackageInfo)
124+
pkg := &PackageInfo{}
113125
if err = cfg.MapTo(pkg); err != nil {
114126
return nil, fmt.Errorf("cfg.MapTo(): %w", err)
115127
}

pkg/apk/types/package_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2026 Chainguard, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package types
216

317
import (
@@ -106,7 +120,6 @@ func TestAsPackage(t *testing.T) {
106120
RepoCommit: "332d2fff53cd4537d415e15e55e8ceb6fe6eaedb",
107121
Replaces: []string{"busybox-initscripts"},
108122
DataHash: "7d3351ac6c3ebaf18182efb5390061f50d077ce5ade60a15909d91278f70ada7",
109-
Triggers: []string{"/bin /usr/bin /sbin /usr/sbin /lib/modules/*"},
110123

111124
BuildTime: time.Unix(1657134589, 0).UTC(),
112125
Checksum: controlHash,

0 commit comments

Comments
 (0)