debian-forge-cli/internal/manifesttest/manifesttest_test.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

35 lines
797 B
Go

package manifesttest_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/osbuild/image-builder-cli/internal/manifesttest"
)
var fakeOsbuildManifest = `{
"version": "2",
"pipelines": [
{
"name": "noop"
},
{
"name": "noop2"
}
]
}`
func TestPipelineNamesFrom(t *testing.T) {
names, err := manifesttest.PipelineNamesFrom([]byte(fakeOsbuildManifest))
assert.NoError(t, err)
assert.Equal(t, []string{"noop", "noop2"}, names)
}
func TestPipelineNamesFromSad(t *testing.T) {
_, err := manifesttest.PipelineNamesFrom([]byte("bad-json"))
assert.ErrorContains(t, err, "cannot unmarshal manifest: invalid char")
_, err = manifesttest.PipelineNamesFrom([]byte("{}"))
assert.ErrorContains(t, err, "cannot find any pipelines in map[]")
}