@@ -20,6 +20,7 @@ import (
2020 "bytes"
2121 "encoding/json"
2222 "fmt"
23+ "math"
2324 "path/filepath"
2425 "strings"
2526 "testing"
@@ -33,6 +34,69 @@ import (
3334 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3435)
3536
37+ func TestCreateConvertParameterValidation (t * testing.T ) {
38+ tests := []struct {
39+ name string
40+ minLayerSize string
41+ spanSize string
42+ expectedError string
43+ }{
44+ {
45+ name : "minLayerSize < 0 fails validation" ,
46+ minLayerSize : "-1" ,
47+ spanSize : "0" ,
48+ expectedError : "min layer size must be >= 0" ,
49+ },
50+ {
51+ name : "spanSize < 0 fails validation" ,
52+ minLayerSize : "0" ,
53+ spanSize : "-1" ,
54+ expectedError : "span size must be >= 0" ,
55+ },
56+ {
57+ name : "minLayerSize > int64.MaxValue fails validation" ,
58+ minLayerSize : fmt .Sprintf ("%d" , uint64 (math .MaxInt64 )+ 1 ),
59+ spanSize : "" ,
60+ expectedError : "for flag -min-layer-size: value out of range" ,
61+ },
62+ {
63+ name : "spanSize > int64.MaxValue fails validation" ,
64+ minLayerSize : "0" ,
65+ spanSize : fmt .Sprintf ("%d" , uint64 (math .MaxInt64 )+ 1 ),
66+ expectedError : "for flag -span-size: value out of range" ,
67+ },
68+ }
69+
70+ sh , done := newSnapshotterBaseShell (t )
71+ defer done ()
72+ rebootContainerd (t , sh , "" , "" )
73+ image := dockerhub (alpineImage )
74+ sh .X ("nerdctl" , "pull" , image .ref )
75+ for _ , test := range tests {
76+ t .Run (test .name , func (t * testing.T ) {
77+ t .Run ("create" , func (t * testing.T ) {
78+ b , err := sh .CombinedOLog ("soci" , "create" , "--min-layer-size" , test .minLayerSize , "--span-size" , test .spanSize , image .ref )
79+ if ! strings .Contains (string (b ), test .expectedError ) {
80+ t .Fatalf ("expected error to contain %q, got %q" , test .expectedError , string (b ))
81+ }
82+ if err == nil {
83+ t .Fatal ("expected error but got nil" )
84+ }
85+ })
86+
87+ t .Run ("convert" , func (t * testing.T ) {
88+ b , err := sh .CombinedOLog ("soci" , "convert" , "--min-layer-size" , test .minLayerSize , "--span-size" , test .spanSize , image .ref , image .ref )
89+ if ! strings .Contains (string (b ), test .expectedError ) {
90+ t .Fatalf ("convert: expected error to contain %q, got %q" , test .expectedError , string (b ))
91+ }
92+ if err == nil {
93+ t .Fatal ("convert: expected error but got nil" )
94+ }
95+ })
96+ })
97+ }
98+ }
99+
36100func TestSociCreateEmptyIndex (t * testing.T ) {
37101 sh , done := newSnapshotterBaseShell (t )
38102 defer done ()
0 commit comments