peterldowns / pgtestdb

quickly run tests in their own temporary, isolated, postgres databases
MIT License
157 stars 13 forks source link

database instance names contain redundant data #16

Open wydengyre opened 5 days ago

wydengyre commented 5 days ago

Database instance names all look like the following:

3aa05350d41d8cd98f00b204e9800998ecf8427e
f1c841c1d41d8cd98f00b204e9800998ecf8427e
e5dde3f7d41d8cd98f00b204e9800998ecf8427e

Note that only the first eight characters change. The remaining are all identical: d41d8cd98f00b204e9800998ecf8427e

This is because the bytes are generated with this function:

https://github.com/peterldowns/pgtestdb/blob/063644d773d90046da7a77d1cf96f0e766758570/internal/withdb/withdb.go#L63

The function doesn't do what it's meant to. hash.Sum(bytes) is not generating a hash of the 4 random bytes, but rather generating a constant hash of empty data and appending it to the four random bytes.

Besides this bug in the code, though, the general idea of taking a hash of the 4 random bytes is odd. It adds no entropy and only serves to make the id longer and unwieldy.

I'd suggest replacing this with a call to stdlib uuid.