Fix digest regex

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2021-02-12 19:51:19 +01:00 committed by GitHub
parent b4ba7f694b
commit 2f63fae705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -67,7 +67,7 @@ func (n *Pusher) Push(f bosonFunc.Function) (digest string, err error) {
return
}
var digestRE = regexp.MustCompile(`digest:\s+sha256:(?P<Digest>\w{64})`)
var digestRE = regexp.MustCompile(`digest:\s+(sha256:\w{64})`)
// parseDigest tries to parse the last line from the output, which holds the pushed image digest
// The output should contain line like this:

24
docker/pusher_test.go Normal file
View File

@ -0,0 +1,24 @@
package docker
import "testing"
func Test_parseDigest(t *testing.T) {
tests := []struct {
name string
arg string
want string
}{
{
name: "basic test",
arg: "latest: digest: sha256:a278a91112d17f8bde6b5f802a3317c7c752cf88078dae6f4b5a0784deb81782 size: 2613",
want: "sha256:a278a91112d17f8bde6b5f802a3317c7c752cf88078dae6f4b5a0784deb81782",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseDigest(tt.arg); got != tt.want {
t.Errorf("parseDigest() = %v, want %v", got, tt.want)
}
})
}
}