@@ -21,9 +21,11 @@ import (
2121 "regexp"
2222 "strings"
2323 "testing"
24+ "time"
2425
2526 "github.com/awslabs/soci-snapshotter/config"
2627 shell "github.com/awslabs/soci-snapshotter/util/dockershell"
28+ "github.com/awslabs/soci-snapshotter/util/testutil"
2729 "github.com/rs/xid"
2830)
2931
@@ -137,3 +139,47 @@ func TestSnapshotterSystemdStartup(t *testing.T) {
137139 })
138140 }
139141}
142+
143+ // TestSnapshotterStartupWithBadConfig ensures snapshotter does not start if snapshotter values are incorrect.
144+ // Note that incorrect fields are ignored by TOML and thus are expected to work
145+ func TestSnapshotterStartupWithBadConfig (t * testing.T ) {
146+ tests := []struct {
147+ name string
148+ opts []snapshotterConfigOpt
149+ expectedErrStr string
150+ }{
151+ {
152+ name : "Bad parallel pull size" ,
153+ opts : []snapshotterConfigOpt {withParallelPullMode (), withConcurrentDownloadChunkSizeStr ("badstring" )},
154+ expectedErrStr : "invalid size format" ,
155+ },
156+ }
157+
158+ for _ , tc := range tests {
159+ t .Run (tc .name , func (tt * testing.T ) {
160+ sh , cleanup := newSnapshotterBaseShell (t )
161+ defer cleanup ()
162+ // rebootContainerd would be ideal here, but that always uses a config,
163+ // so we just manually start SOCI with/without a config file.
164+ err := testutil .KillMatchingProcess (sh , "soci-snapshotter-grpc" )
165+ if err != nil {
166+ sh .Fatal ("failed to kill soci: %v" , err )
167+ }
168+ configToml := getSnapshotterConfigToml (t , tc .opts ... )
169+ snRunCmd := []string {"/usr/local/bin/soci-snapshotter-grpc" , "--log-level" , sociLogLevel }
170+ snRunCmd = addConfig (t , sh , configToml , snRunCmd ... )
171+
172+ errCh := make (chan error , 1 )
173+ go func () {
174+ _ , err := sh .OLog (snRunCmd ... )
175+ errCh <- err
176+ }()
177+
178+ select {
179+ case <- errCh :
180+ case <- time .After (2 * time .Second ):
181+ t .Fatalf ("expected err %s but snapshotter did not fail within 2 seconds" , tc .expectedErrStr )
182+ }
183+ })
184+ }
185+ }
0 commit comments