Use map for stream processors
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
@@ -63,13 +63,11 @@ type Config struct {
|
||||
// Imports are additional file path list to config files that can overwrite main config file fields
|
||||
Imports []string `toml:"imports"`
|
||||
|
||||
StreamProcessors []StreamProcessor `toml:"stream_processors"`
|
||||
StreamProcessors map[string]StreamProcessor `toml:"stream_processors"`
|
||||
}
|
||||
|
||||
// StreamProcessor provides configuration for diff content processors
|
||||
type StreamProcessor struct {
|
||||
// ID of the processor, also used to fetch the specific payload
|
||||
ID string `toml:"id"`
|
||||
// Accepts specific media-types
|
||||
Accepts []string `toml:"accepts"`
|
||||
// Returns the media-type
|
||||
|
||||
@@ -86,6 +86,11 @@ func TestLoadSingleConfig(t *testing.T) {
|
||||
data := `
|
||||
version = 2
|
||||
root = "/var/lib/containerd"
|
||||
|
||||
[stream_processors]
|
||||
[stream_processors."io.containerd.processor.v1.pigz"]
|
||||
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
|
||||
path = "unpigz"
|
||||
`
|
||||
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||
assert.NilError(t, err)
|
||||
@@ -100,6 +105,12 @@ root = "/var/lib/containerd"
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 2, out.Version)
|
||||
assert.Equal(t, "/var/lib/containerd", out.Root)
|
||||
assert.DeepEqual(t, map[string]StreamProcessor{
|
||||
"io.containerd.processor.v1.pigz": {
|
||||
Accepts: []string{"application/vnd.docker.image.rootfs.diff.tar.gzip"},
|
||||
Path: "unpigz",
|
||||
},
|
||||
}, out.StreamProcessors)
|
||||
}
|
||||
|
||||
func TestLoadConfigWithImports(t *testing.T) {
|
||||
|
||||
@@ -89,8 +89,8 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, p := range config.StreamProcessors {
|
||||
diff.RegisterProcessor(diff.BinaryHandler(p.ID, p.Returns, p.Accepts, p.Path, p.Args))
|
||||
for id, p := range config.StreamProcessors {
|
||||
diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args))
|
||||
}
|
||||
|
||||
serverOpts := []grpc.ServerOption{
|
||||
|
||||
Reference in New Issue
Block a user