Skip to content

Commit

Permalink
cmd/otk: add tests for osbuild-make-ostree-source
Browse files Browse the repository at this point in the history
  • Loading branch information
achilleas-k authored and mvo5 committed Oct 11, 2024
1 parent a522740 commit 302881b
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/otk/osbuild-make-ostree-source/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

var (
Run = run
)
85 changes: 85 additions & 0 deletions cmd/otk/osbuild-make-ostree-source/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main_test

import (
"bytes"
"testing"

sourcemaker "github.com/osbuild/images/cmd/otk/osbuild-make-ostree-source"
"github.com/stretchr/testify/require"
)

func TestSourceMakerBasic(t *testing.T) {
require := require.New(t)

input := `
{
"tree": {
"const": {
"ref": "does/not/matter",
"checksum": "d04105393ca0617856b34f897842833d785522e41617e17dca2063bf97e294ef",
"url": "https://ostree.example.org/repo"
}
}
}`

expOutput := `{
"tree": {
"org.osbuild.ostree": {
"items": {
"d04105393ca0617856b34f897842833d785522e41617e17dca2063bf97e294ef": {
"remote": {
"url": "https://ostree.example.org/repo"
}
}
}
}
}
}
`

inpBuf := bytes.NewBuffer([]byte(input))
outBuf := &bytes.Buffer{}

require.NoError(sourcemaker.Run(inpBuf, outBuf))
require.Equal(expOutput, outBuf.String())
}

func TestSourceMakerWithSecrets(t *testing.T) {
require := require.New(t)

input := `
{
"tree": {
"const": {
"ref": "does/not/matter",
"checksum": "d04105393ca0617856b34f897842833d785522e41617e17dca2063bf97e294ef",
"url": "https://ostree.example.org/repo",
"secrets": "org.osbuild.rhsm.consumer"
}
}
}`

expOutput := `{
"tree": {
"org.osbuild.ostree": {
"items": {
"d04105393ca0617856b34f897842833d785522e41617e17dca2063bf97e294ef": {
"remote": {
"url": "https://ostree.example.org/repo",
"secrets": {
"name": "org.osbuild.rhsm.consumer"
}
}
}
}
}
}
}
`

inpBuf := bytes.NewBuffer([]byte(input))
outBuf := &bytes.Buffer{}

require.NoError(sourcemaker.Run(inpBuf, outBuf))
require.Equal(expOutput, outBuf.String())
}

0 comments on commit 302881b

Please sign in to comment.