github.com/hernad/nomad@v1.6.112/helper/uuid/uuid_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package uuid
     5  
     6  import (
     7  	"regexp"
     8  	"testing"
     9  )
    10  
    11  func TestGenerate(t *testing.T) {
    12  	prev := Generate()
    13  	for i := 0; i < 100; i++ {
    14  		id := Generate()
    15  		if prev == id {
    16  			t.Fatalf("Should get a new ID!")
    17  		}
    18  
    19  		matched, err := regexp.MatchString(
    20  			"[\\da-f]{8}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{4}-[\\da-f]{12}", id)
    21  		if !matched || err != nil {
    22  			t.Fatalf("expected match %s %v %s", id, matched, err)
    23  		}
    24  	}
    25  }