@@ -6,6 +6,7 @@ package skills
66import (
77 "testing"
88
9+ ocispec "github.com/opencontainers/image-spec/specs-go/v1"
910 "github.com/stretchr/testify/assert"
1011 "github.com/stretchr/testify/require"
1112)
@@ -15,16 +16,16 @@ func TestSkillConfigFromImageConfig(t *testing.T) {
1516
1617 tests := []struct {
1718 name string
18- config * ImageConfig
19+ config * ocispec. Image
1920 wantName string
2021 wantErr bool
2122 wantTools []string
2223 wantFiles []string
2324 }{
2425 {
2526 name : "all fields populated" ,
26- config : & ImageConfig {
27- Config : ImageConfigData {
27+ config : & ocispec. Image {
28+ Config : ocispec. ImageConfig {
2829 Labels : map [string ]string {
2930 LabelSkillName : "my-skill" ,
3031 LabelSkillDescription : "A test skill" ,
@@ -41,8 +42,8 @@ func TestSkillConfigFromImageConfig(t *testing.T) {
4142 },
4243 {
4344 name : "minimal config" ,
44- config : & ImageConfig {
45- Config : ImageConfigData {
45+ config : & ocispec. Image {
46+ Config : ocispec. ImageConfig {
4647 Labels : map [string ]string {
4748 LabelSkillName : "minimal-skill" ,
4849 },
@@ -57,15 +58,15 @@ func TestSkillConfigFromImageConfig(t *testing.T) {
5758 },
5859 {
5960 name : "nil labels" ,
60- config : & ImageConfig {
61- Config : ImageConfigData {Labels : nil },
61+ config : & ocispec. Image {
62+ Config : ocispec. ImageConfig {Labels : nil },
6263 },
6364 wantErr : true ,
6465 },
6566 {
6667 name : "missing name" ,
67- config : & ImageConfig {
68- Config : ImageConfigData {
68+ config : & ocispec. Image {
69+ Config : ocispec. ImageConfig {
6970 Labels : map [string ]string {
7071 LabelSkillDescription : "no name" ,
7172 },
@@ -75,8 +76,8 @@ func TestSkillConfigFromImageConfig(t *testing.T) {
7576 },
7677 {
7778 name : "invalid allowed tools JSON" ,
78- config : & ImageConfig {
79- Config : ImageConfigData {
79+ config : & ocispec. Image {
80+ Config : ocispec. ImageConfig {
8081 Labels : map [string ]string {
8182 LabelSkillName : "bad-tools" ,
8283 LabelSkillAllowedTools : "not-json" ,
@@ -87,8 +88,8 @@ func TestSkillConfigFromImageConfig(t *testing.T) {
8788 },
8889 {
8990 name : "invalid files JSON" ,
90- config : & ImageConfig {
91- Config : ImageConfigData {
91+ config : & ocispec. Image {
92+ Config : ocispec. ImageConfig {
9293 Labels : map [string ]string {
9394 LabelSkillName : "bad-files" ,
9495 LabelSkillFiles : "not-json" ,
@@ -126,18 +127,23 @@ func TestParsePlatform(t *testing.T) {
126127 tests := []struct {
127128 name string
128129 input string
129- want Platform
130+ want ocispec. Platform
130131 wantErr bool
131132 }{
132133 {
133134 name : "linux/amd64" ,
134135 input : "linux/amd64" ,
135- want : Platform {OS : "linux" , Architecture : "amd64" },
136+ want : ocispec. Platform {OS : "linux" , Architecture : "amd64" },
136137 },
137138 {
138139 name : "linux/arm64" ,
139140 input : "linux/arm64" ,
140- want : Platform {OS : "linux" , Architecture : "arm64" },
141+ want : ocispec.Platform {OS : "linux" , Architecture : "arm64" },
142+ },
143+ {
144+ name : "linux/arm/v7" ,
145+ input : "linux/arm/v7" ,
146+ want : ocispec.Platform {OS : "linux" , Architecture : "arm" , Variant : "v7" },
141147 },
142148 {
143149 name : "no slash" ,
@@ -146,7 +152,7 @@ func TestParsePlatform(t *testing.T) {
146152 },
147153 {
148154 name : "too many parts" ,
149- input : "linux/amd64/v8" ,
155+ input : "linux/amd64/v8/extra " ,
150156 wantErr : true ,
151157 },
152158 {
@@ -159,6 +165,11 @@ func TestParsePlatform(t *testing.T) {
159165 input : "linux/" ,
160166 wantErr : true ,
161167 },
168+ {
169+ name : "empty variant" ,
170+ input : "linux/arm/" ,
171+ wantErr : true ,
172+ },
162173 }
163174
164175 for _ , tt := range tests {
@@ -179,8 +190,45 @@ func TestParsePlatform(t *testing.T) {
179190func TestPlatformString (t * testing.T ) {
180191 t .Parallel ()
181192
182- p := Platform {OS : "linux" , Architecture : "amd64" }
183- assert .Equal (t , "linux/amd64" , p .String ())
193+ tests := []struct {
194+ name string
195+ platform ocispec.Platform
196+ want string
197+ }{
198+ {
199+ name : "os/arch" ,
200+ platform : ocispec.Platform {OS : "linux" , Architecture : "amd64" },
201+ want : "linux/amd64" ,
202+ },
203+ {
204+ name : "os/arch/variant" ,
205+ platform : ocispec.Platform {OS : "linux" , Architecture : "arm" , Variant : "v7" },
206+ want : "linux/arm/v7" ,
207+ },
208+ }
209+
210+ for _ , tt := range tests {
211+ t .Run (tt .name , func (t * testing.T ) {
212+ t .Parallel ()
213+ assert .Equal (t , tt .want , PlatformString (tt .platform ))
214+ })
215+ }
216+ }
217+
218+ func TestParsePlatform_PlatformString_Roundtrip (t * testing.T ) {
219+ t .Parallel ()
220+
221+ platforms := []ocispec.Platform {
222+ {OS : "linux" , Architecture : "amd64" },
223+ {OS : "linux" , Architecture : "arm64" },
224+ {OS : "linux" , Architecture : "arm" , Variant : "v7" },
225+ }
226+
227+ for _ , p := range platforms {
228+ parsed , err := ParsePlatform (PlatformString (p ))
229+ require .NoError (t , err )
230+ assert .Equal (t , p , parsed )
231+ }
184232}
185233
186234func TestParseRequiresAnnotation (t * testing.T ) {
@@ -238,6 +286,6 @@ func TestDefaultPlatforms(t *testing.T) {
238286 t .Parallel ()
239287
240288 require .Len (t , DefaultPlatforms , 2 )
241- assert .Equal (t , Platform {OS : "linux" , Architecture : "amd64" }, DefaultPlatforms [0 ])
242- assert .Equal (t , Platform {OS : "linux" , Architecture : "arm64" }, DefaultPlatforms [1 ])
289+ assert .Equal (t , ocispec. Platform {OS : "linux" , Architecture : "amd64" }, DefaultPlatforms [0 ])
290+ assert .Equal (t , ocispec. Platform {OS : "linux" , Architecture : "arm64" }, DefaultPlatforms [1 ])
243291}
0 commit comments