debian-forge-cli/internal/manifesttest/manifesttest.go
Michael Vogt 5a6ee5c1ca pkg: add new manifesttest package with test helpers
This commit adds a new `manifesttest` that helps sharing code
when testing generated osbuild manifests.
2024-12-16 07:54:45 +00:00

27 lines
806 B
Go

package manifesttest
import (
"encoding/json"
"fmt"
)
// PipelineNamesFrom will return all pipeline names from an osbuild
// json manifest. It will error on missing pipelines.
//
// TODO: move to images:pkg/manifesttest
func PipelineNamesFrom(osbuildManifest []byte) ([]string, error) {
var manifest map[string]interface{}
if err := json.Unmarshal(osbuildManifest, &manifest); err != nil {
return nil, fmt.Errorf("cannot unmarshal manifest: %w", err)
}
if manifest["pipelines"] == nil {
return nil, fmt.Errorf("cannot find any pipelines in %v", manifest)
}
pipelines := manifest["pipelines"].([]interface{})
pipelineNames := make([]string, len(pipelines))
for idx, pi := range pipelines {
pipelineNames[idx] = pi.(map[string]interface{})["name"].(string)
}
return pipelineNames, nil
}