mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-13 21:56:38 +01:00
feat(clean): log removed/untagged images (#1466)
This commit is contained in:
parent
dd1ec09668
commit
0a5bd54fb7
5 changed files with 143 additions and 9 deletions
24
internal/util/rand_sha256.go
Normal file
24
internal/util/rand_sha256.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
// GenerateRandomSHA256 generates a random 64 character SHA 256 hash string
|
||||
func GenerateRandomSHA256() string {
|
||||
return GenerateRandomPrefixedSHA256()[7:]
|
||||
}
|
||||
|
||||
// GenerateRandomPrefixedSHA256 generates a random 64 character SHA 256 hash string, prefixed with `sha256:`
|
||||
func GenerateRandomPrefixedSHA256() string {
|
||||
hash := make([]byte, 32)
|
||||
_, _ = rand.Read(hash)
|
||||
sb := bytes.NewBufferString("sha256:")
|
||||
sb.Grow(64)
|
||||
for _, h := range hash {
|
||||
_, _ = fmt.Fprintf(sb, "%02x", h)
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSliceEqual_True(t *testing.T) {
|
||||
|
|
@ -62,3 +64,15 @@ func TestStructMapSubtract(t *testing.T) {
|
|||
assert.Equal(t, map[string]struct{}{"a": x, "b": x, "c": x}, m1)
|
||||
assert.Equal(t, map[string]struct{}{"a": x, "c": x}, m2)
|
||||
}
|
||||
|
||||
// GenerateRandomSHA256 generates a random 64 character SHA 256 hash string
|
||||
func TestGenerateRandomSHA256(t *testing.T) {
|
||||
res := GenerateRandomSHA256()
|
||||
assert.Len(t, res, 64)
|
||||
assert.NotContains(t, res, "sha256:")
|
||||
}
|
||||
|
||||
func TestGenerateRandomPrefixedSHA256(t *testing.T) {
|
||||
res := GenerateRandomPrefixedSHA256()
|
||||
assert.Regexp(t, regexp.MustCompile("sha256:[0-9|a-f]{64}"), res)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue