mirror of
https://github.com/getsops/sops.git
synced 2026-02-05 12:45:21 +01:00
sops_test: add more tests on errors
Signed-off-by: Sebastien Duthil <duthils@duthils.net>
This commit is contained in:
65
sops_test.go
65
sops_test.go
@@ -844,6 +844,23 @@ func TestDecrypt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type WrongType struct{}
|
||||
|
||||
func TestEncryptWrongType(t *testing.T) {
|
||||
branches := TreeBranches{
|
||||
TreeBranch{
|
||||
TreeItem{
|
||||
Key: "foo",
|
||||
Value: WrongType{},
|
||||
},
|
||||
},
|
||||
}
|
||||
tree := Tree{Branches: branches, Metadata: Metadata{UnencryptedSuffix: DefaultUnencryptedSuffix}}
|
||||
result, err := tree.Encrypt(bytes.Repeat([]byte{'f'}, 32), MockCipher{})
|
||||
assert.Equal(t, "", result)
|
||||
assert.ErrorContains(t, err, "unknown type: sops.WrongType")
|
||||
}
|
||||
|
||||
func TestTruncateTree(t *testing.T) {
|
||||
tree := TreeBranch{
|
||||
TreeItem{
|
||||
@@ -875,6 +892,45 @@ func TestTruncateTree(t *testing.T) {
|
||||
assert.Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func TestTruncateTreeNotFound(t *testing.T) {
|
||||
tree := TreeBranch{
|
||||
TreeItem{
|
||||
Key: "foo",
|
||||
Value: 2,
|
||||
},
|
||||
}
|
||||
result, err := tree.Truncate([]interface{}{"baz"})
|
||||
assert.ErrorContains(t, err, "baz")
|
||||
assert.Nil(t, result, "Truncate result was not nil upon %s", err)
|
||||
}
|
||||
|
||||
func TestTruncateTreeNotArray(t *testing.T) {
|
||||
tree := TreeBranch{
|
||||
TreeItem{
|
||||
Key: "foo",
|
||||
Value: 2,
|
||||
},
|
||||
}
|
||||
result, err := tree.Truncate([]interface{}{"foo", 99})
|
||||
assert.ErrorContains(t, err, "99")
|
||||
assert.Nil(t, result, "Truncate result was not nil upon %s", err)
|
||||
}
|
||||
|
||||
func TestTruncateTreeArrayOutOfBounds(t *testing.T) {
|
||||
tree := TreeBranch{
|
||||
TreeItem{
|
||||
Key: "foo",
|
||||
Value: []interface{}{
|
||||
"one",
|
||||
"two",
|
||||
},
|
||||
},
|
||||
}
|
||||
result, err := tree.Truncate([]interface{}{"foo", 99})
|
||||
assert.ErrorContains(t, err, "99")
|
||||
assert.Nil(t, result, "Truncate result was not nil upon %s", err)
|
||||
}
|
||||
|
||||
func TestEncryptComments(t *testing.T) {
|
||||
tree := Tree{
|
||||
Branches: TreeBranches{
|
||||
@@ -1360,8 +1416,9 @@ func TestUnsetKeyNotFound(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
unset, err := branch.Unset([]interface{}{"foo", "unknown"})
|
||||
assert.Equal(t, err.(*SopsKeyNotFound).Key, "unknown")
|
||||
unset, err := branch.Unset([]interface{}{"foo", "unknown-value"})
|
||||
assert.Equal(t, err.(*SopsKeyNotFound).Key, "unknown-value")
|
||||
assert.ErrorContains(t, err, "unknown-value")
|
||||
assert.Nil(t, unset, "Unset result was not nil upon %s", err)
|
||||
}
|
||||
|
||||
@@ -1435,6 +1492,10 @@ func TestEmitAsMap(t *testing.T) {
|
||||
Key: "number",
|
||||
Value: 42,
|
||||
},
|
||||
TreeItem{
|
||||
Key: Comment{"comment"},
|
||||
Value: nil,
|
||||
},
|
||||
},
|
||||
TreeBranch{
|
||||
TreeItem{
|
||||
|
||||
Reference in New Issue
Block a user