Skip to content

Commit

Permalink
tests/converter: modify unpack testcase
Browse files Browse the repository at this point in the history
This patch modifies the unpack testcase to keep consistent with the
new `nydus-image unpack` interface in nydus-image.

Signed-off-by: Yifan Zhao <[email protected]>
  • Loading branch information
SToPire committed Sep 1, 2024
1 parent 8fa319b commit 608c7df
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/converter/tool/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,41 @@ func Unpack(option UnpackOption) error {
}

if option.BackendConfigPath != "" {
args = append(args, "--backend-config", option.BackendConfigPath)
configFile, err := os.Open(option.BackendConfigPath)
if err != nil {
return errors.Wrapf(err, "fail to open backend config file %s", option.BackendConfigPath)
}
defer configFile.Close()

configBytes, err := os.ReadFile(option.BackendConfigPath)
if err != nil {
return errors.Wrapf(err, "fail to read backend config file %s", option.BackendConfigPath)
}

var config map[string]interface{}
if err := json.Unmarshal(configBytes, &config); err != nil {
return errors.Wrapf(err, "fail to unmarshal backend config file %s", option.BackendConfigPath)
}

backendConfigType, ok := config["backend"].(map[string]interface{})["type"]
if !ok {
return errors.New("backend config file should contain a valid backend type")
}

backendConfig, ok := config["backend"].(map[string]interface{})[backendConfigType.(string)]
if !ok {
return errors.New("failed to get backend config with type " + backendConfigType.(string))
}

backendConfigBytes, err := json.Marshal(backendConfig)
if err != nil {
return errors.Wrapf(err, "fail to marshal backend config %v", backendConfig)
}

logrus.Errorf("Backend config: %s", backendConfigBytes)

args = append(args, "--backend-type", backendConfigType.(string))
args = append(args, "--backend-config", string(backendConfigBytes))
} else if option.BlobPath != "" {
args = append(args, "--blob", option.BlobPath)
}
Expand Down

0 comments on commit 608c7df

Please sign in to comment.