From 1a2f4be378717708e42deeaa4e0feddebeb72fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 8 Apr 2025 11:08:01 +0200 Subject: [PATCH] Add unit test for describe-image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a unit test for testing that providing only the required command line arguments produces expected output. Signed-off-by: Tomáš Hozza --- cmd/image-builder/main_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index b3eb469..bb7bdb7 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -27,6 +27,7 @@ import ( main "github.com/osbuild/image-builder-cli/cmd/image-builder" "github.com/osbuild/image-builder-cli/internal/manifesttest" "github.com/osbuild/image-builder-cli/internal/testutil" + "github.com/osbuild/images/pkg/arch" ) func init() { @@ -709,6 +710,33 @@ type: qcow2 arch: x86_64`) } +func TestDescribeImageMinimal(t *testing.T) { + restore := main.MockNewRepoRegistry(testrepos.New) + defer restore() + + restore = main.MockDistroGetHostDistroName(func() (string, error) { + return "centos-9", nil + }) + defer restore() + + restore = main.MockOsArgs([]string{ + "describe", + "qcow2", + }) + defer restore() + + var fakeStdout bytes.Buffer + restore = main.MockOsStdout(&fakeStdout) + defer restore() + + err := main.Run() + assert.NoError(t, err) + + assert.Contains(t, fakeStdout.String(), fmt.Sprintf(`distro: centos-9 +type: qcow2 +arch: %s`, arch.Current().String())) +} + func TestProgressFromCmd(t *testing.T) { cmd := &cobra.Command{} cmd.Flags().String("progress", "auto", "")