mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
a7aa2c8ad2
The current Dev version of TarSum includes hashing of extended file attributes and omits inclusion of modified time headers. I refactored the logic around the version differences to make it more clear that the difference between versions is in how tar headers are selected and ordered. TarSum Version 1 is now declared with the new Dev version continuing to track it. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package tarsum
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestVersion(t *testing.T) {
|
|
expected := "tarsum"
|
|
var v Version
|
|
if v.String() != expected {
|
|
t.Errorf("expected %q, got %q", expected, v.String())
|
|
}
|
|
|
|
expected = "tarsum.v1"
|
|
v = 1
|
|
if v.String() != expected {
|
|
t.Errorf("expected %q, got %q", expected, v.String())
|
|
}
|
|
|
|
expected = "tarsum.dev"
|
|
v = 2
|
|
if v.String() != expected {
|
|
t.Errorf("expected %q, got %q", expected, v.String())
|
|
}
|
|
}
|
|
|
|
func TestGetVersion(t *testing.T) {
|
|
testSet := []struct {
|
|
Str string
|
|
Expected Version
|
|
}{
|
|
{"tarsum+sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b", Version0},
|
|
{"tarsum+sha256", Version0},
|
|
{"tarsum", Version0},
|
|
{"tarsum.dev", VersionDev},
|
|
{"tarsum.dev+sha256:deadbeef", VersionDev},
|
|
}
|
|
|
|
for _, ts := range testSet {
|
|
v, err := GetVersionFromTarsum(ts.Str)
|
|
if err != nil {
|
|
t.Fatalf("%q : %s", err, ts.Str)
|
|
}
|
|
if v != ts.Expected {
|
|
t.Errorf("expected %d (%q), got %d (%q)", ts.Expected, ts.Expected, v, v)
|
|
}
|
|
}
|
|
|
|
// test one that does not exist, to ensure it errors
|
|
str := "weak+md5:abcdeabcde"
|
|
_, err := GetVersionFromTarsum(str)
|
|
if err != ErrNotVersion {
|
|
t.Fatalf("%q : %s", err, str)
|
|
}
|
|
}
|