debian-forge-composer/internal/osbuild2/result_test.go
Ondřej Budai ea8d080c8a osbuild1/result: fix conversion of success field from v2
When a stage is successful in a manifest v2, the success field is omitted from
the result. In other words, the default value of the success field is true
which is against the default value of boolean in Go. This commit implements
a workaround.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2021-03-19 18:50:31 +01:00

28 lines
561 B
Go

package osbuild2
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStageResult_UnmarshalJSON(t *testing.T) {
cases := []struct {
input string
success bool
}{
{input: `{}`, success: true},
{input: `{"success": true}`, success: true},
{input: `{"success": false}`, success: false},
}
for _, c := range cases {
t.Run(c.input, func(t *testing.T) {
var result StageResult
err := json.Unmarshal([]byte(c.input), &result)
assert.NoError(t, err)
assert.Equal(t, c.success, result.Success)
})
}
}