(t *testing.T)
| 1550 | } |
| 1551 | |
| 1552 | func TestSortKeyGroupIndices(t *testing.T) { |
| 1553 | t.Run("default order", func(t *testing.T) { |
| 1554 | group := KeyGroup{&hcvault.MasterKey{}, &age.MasterKey{}, &pgp.MasterKey{}} |
| 1555 | expected := []int{1, 2, 0} |
| 1556 | indices := sortKeyGroupIndices(group, DefaultDecryptionOrder) |
| 1557 | assert.Equal(t, expected, indices) |
| 1558 | }) |
| 1559 | |
| 1560 | t.Run("different keygroup", func(t *testing.T) { |
| 1561 | group := KeyGroup{&hcvault.MasterKey{}, &pgp.MasterKey{}, &age.MasterKey{}} |
| 1562 | expected := []int{2, 1, 0} |
| 1563 | indices := sortKeyGroupIndices(group, DefaultDecryptionOrder) |
| 1564 | assert.Equal(t, expected, indices) |
| 1565 | }) |
| 1566 | |
| 1567 | t.Run("repeated key", func(t *testing.T) { |
| 1568 | group := KeyGroup{&pgp.MasterKey{}, &hcvault.MasterKey{}, &pgp.MasterKey{}, &age.MasterKey{}} |
| 1569 | expected := []int{3, 0, 2, 1} |
| 1570 | indices := sortKeyGroupIndices(group, DefaultDecryptionOrder) |
| 1571 | assert.Equal(t, expected, indices) |
| 1572 | }) |
| 1573 | |
| 1574 | t.Run("full order", func(t *testing.T) { |
| 1575 | group := KeyGroup{&hcvault.MasterKey{}, &pgp.MasterKey{}, &age.MasterKey{}} |
| 1576 | expected := []int{1, 2, 0} |
| 1577 | indices := sortKeyGroupIndices(group, []string{"pgp", "age", "hc_vault"}) |
| 1578 | assert.Equal(t, expected, indices) |
| 1579 | }) |
| 1580 | |
| 1581 | t.Run("empty order", func(t *testing.T) { |
| 1582 | group := KeyGroup{&hcvault.MasterKey{}, &pgp.MasterKey{}, &age.MasterKey{}} |
| 1583 | expected := []int{0, 1, 2} |
| 1584 | indices := sortKeyGroupIndices(group, []string{}) |
| 1585 | assert.Equal(t, expected, indices) |
| 1586 | }) |
| 1587 | |
| 1588 | t.Run("one match", func(t *testing.T) { |
| 1589 | group := KeyGroup{&hcvault.MasterKey{}, &pgp.MasterKey{}, &age.MasterKey{}} |
| 1590 | expected := []int{2, 0, 1} |
| 1591 | indices := sortKeyGroupIndices(group, []string{"azure_kv", "age"}) |
| 1592 | assert.Equal(t, expected, indices) |
| 1593 | }) |
| 1594 | |
| 1595 | t.Run("nonmatching order", func(t *testing.T) { |
| 1596 | group := KeyGroup{&pgp.MasterKey{}, &hcvault.MasterKey{}, &age.MasterKey{}} |
| 1597 | expected := []int{0, 1, 2} |
| 1598 | indices := sortKeyGroupIndices(group, []string{"azure_kv"}) |
| 1599 | assert.Equal(t, expected, indices) |
| 1600 | }) |
| 1601 | |
| 1602 | t.Run("nonexistent keys", func(t *testing.T) { |
| 1603 | group := KeyGroup{&hcvault.MasterKey{}, &pgp.MasterKey{}, &age.MasterKey{}} |
| 1604 | expected := []int{2, 1, 0} |
| 1605 | indices := sortKeyGroupIndices(group, []string{"dummy1", "age", "dummy2", "pgp", "dummy3"}) |
| 1606 | assert.Equal(t, expected, indices) |
| 1607 | }) |
| 1608 | } |
nothing calls this directly
no test coverage detected