github.com/dougm/docker@v1.5.0/pkg/tarsum/versioning_test.go (about)

     1  package tarsum
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestVersion(t *testing.T) {
     8  	expected := "tarsum"
     9  	var v Version
    10  	if v.String() != expected {
    11  		t.Errorf("expected %q, got %q", expected, v.String())
    12  	}
    13  
    14  	expected = "tarsum.v1"
    15  	v = 1
    16  	if v.String() != expected {
    17  		t.Errorf("expected %q, got %q", expected, v.String())
    18  	}
    19  
    20  	expected = "tarsum.dev"
    21  	v = 2
    22  	if v.String() != expected {
    23  		t.Errorf("expected %q, got %q", expected, v.String())
    24  	}
    25  }
    26  
    27  func TestGetVersion(t *testing.T) {
    28  	testSet := []struct {
    29  		Str      string
    30  		Expected Version
    31  	}{
    32  		{"tarsum+sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b", Version0},
    33  		{"tarsum+sha256", Version0},
    34  		{"tarsum", Version0},
    35  		{"tarsum.dev", VersionDev},
    36  		{"tarsum.dev+sha256:deadbeef", VersionDev},
    37  	}
    38  
    39  	for _, ts := range testSet {
    40  		v, err := GetVersionFromTarsum(ts.Str)
    41  		if err != nil {
    42  			t.Fatalf("%q : %s", err, ts.Str)
    43  		}
    44  		if v != ts.Expected {
    45  			t.Errorf("expected %d (%q), got %d (%q)", ts.Expected, ts.Expected, v, v)
    46  		}
    47  	}
    48  
    49  	// test one that does not exist, to ensure it errors
    50  	str := "weak+md5:abcdeabcde"
    51  	_, err := GetVersionFromTarsum(str)
    52  	if err != ErrNotVersion {
    53  		t.Fatalf("%q : %s", err, str)
    54  	}
    55  }