...

Source file src/github.com/docker/distribution/uuid/uuid_test.go

Documentation: github.com/docker/distribution/uuid

     1  package uuid
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  const iterations = 1000
     8  
     9  func TestUUID4Generation(t *testing.T) {
    10  	for i := 0; i < iterations; i++ {
    11  		u := Generate()
    12  
    13  		if u[6]&0xf0 != 0x40 {
    14  			t.Fatalf("version byte not correctly set: %v, %08b %08b", u, u[6], u[6]&0xf0)
    15  		}
    16  
    17  		if u[8]&0xc0 != 0x80 {
    18  			t.Fatalf("top order 8th byte not correctly set: %v, %b", u, u[8])
    19  		}
    20  	}
    21  }
    22  
    23  func TestParseAndEquality(t *testing.T) {
    24  	for i := 0; i < iterations; i++ {
    25  		u := Generate()
    26  
    27  		parsed, err := Parse(u.String())
    28  		if err != nil {
    29  			t.Fatalf("error parsing uuid %v: %v", u, err)
    30  		}
    31  
    32  		if parsed != u {
    33  			t.Fatalf("parsing round trip failed: %v != %v", parsed, u)
    34  		}
    35  	}
    36  
    37  	for _, c := range []string{
    38  		"bad",
    39  		"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",    // correct length, incorrect format
    40  		"  20cc7775-2671-43c7-8742-51d1cfa23258",  // leading space
    41  		"20cc7775-2671-43c7-8742-51d1cfa23258   ", // trailing space
    42  		"00000000-0000-0000-0000-x00000000000",    // out of range character
    43  	} {
    44  		if _, err := Parse(c); err == nil {
    45  			t.Fatalf("parsing %q should have failed", c)
    46  		}
    47  	}
    48  }
    49  

View as plain text