1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
package imagebuildah
import (
"encoding/json"
"strconv"
"testing"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHistoryEntriesEqual(t *testing.T) {
testCases := []struct {
a, b string
equal bool
}{
{
a: `{}`,
b: `{}`,
equal: true,
},
{
a: `{"created":"2020-06-17T00:22:25.47282687Z"}`,
b: `{"created":"2020-06-17T00:22:25.47282687Z"}`,
equal: true,
},
{
a: `{"created":"2020-07-16T12:38:26.733333497-04:00"}`,
b: `{"created":"2020-07-16T12:38:26.733333497-04:00"}`,
equal: true,
},
{
a: `{"created":"2020-07-16T12:38:26.733333497-04:00"}`,
b: `{"created":"2020-07-16T12:38:26.733333497Z"}`,
equal: false,
},
{
a: `{"created":"2020-07-16T12:38:26.733333497Z"}`,
b: `{}`,
equal: false,
},
{
a: `{}`,
b: `{"created":"2020-07-16T12:38:26.733333497Z"}`,
equal: false,
},
{
a: `{"comment":"thing"}`,
b: `{"comment":"thing"}`,
equal: true,
},
{
a: `{"comment":"thing","ignored-field-for-testing":"ignored"}`,
b: `{"comment":"thing"}`,
equal: true,
},
{
a: `{"CoMmEnT":"thing"}`,
b: `{"comment":"thing"}`,
equal: true,
},
{
a: `{"comment":"thing"}`,
b: `{"comment":"things"}`,
equal: false,
},
{
a: `{"author":"respected"}`,
b: `{"author":"respected"}`,
equal: true,
},
{
a: `{"author":"respected"}`,
b: `{"author":"discredited"}`,
equal: false,
},
{
a: `{"created_by":"actions"}`,
b: `{"created_by":"actions"}`,
equal: true,
},
{
a: `{"created_by":"jiggery"}`,
b: `{"created_by":"pokery"}`,
equal: false,
},
}
for i := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
var a, b v1.History
err := json.Unmarshal([]byte(testCases[i].a), &a)
require.Nil(t, err, "error unmarshalling history %q: %v", testCases[i].a, err)
err = json.Unmarshal([]byte(testCases[i].b), &b)
require.Nil(t, err, "error unmarshalling history %q: %v", testCases[i].b, err)
equal := historyEntriesEqual(a, b)
assert.Equal(t, testCases[i].equal, equal, "historyEntriesEqual(%q, %q) != %v", testCases[i].a, testCases[i].b, testCases[i].equal)
})
}
}
|