github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/uuid/uuid.go (about) 1 package uuid 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/google/uuid" 8 ) 9 10 var newUUID func() uuid.UUID = uuid.New 11 12 // SetFakeUUID sets a fake UUID for testing. 13 // The 'format' is used to generate a fake UUID and 14 // must contain a single '%d' which will be replaced with a counter. 15 func SetFakeUUID(t *testing.T, format string) { 16 var count int 17 newUUID = func() uuid.UUID { 18 count++ 19 return uuid.Must(uuid.Parse(fmt.Sprintf(format, count))) 20 } 21 t.Cleanup(func() { 22 newUUID = uuid.New 23 }) 24 } 25 26 func New() uuid.UUID { 27 return newUUID() 28 }