mirror of https://github.com/databricks/cli.git
feat: Implement fixed modification time and deterministic wheel filename in test
This commit is contained in:
parent
f681a9261f
commit
5c46e62374
|
@ -186,9 +186,19 @@ func TestPrebuilt(t *testing.T) {
|
||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// AI TODO: set mtime of prebuiltWheel to fixed value 2025-03-05 14:15:55.123456789. Simplify the code below to hardcode names based on this value.
|
// Set fixed modification time for deterministic testing
|
||||||
|
fixedTime := time.Date(2025, 3, 5, 14, 15, 55, 123456789, time.UTC)
|
||||||
|
err := os.Chtimes(prebuiltWheel, fixedTime, fixedTime)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// With the fixed time, we know exactly what the output filename will be
|
||||||
|
expectedVersion := "0.0.1+20250305141555.12"
|
||||||
|
expectedFilename := "my_test_code-" + expectedVersion + "-py3-none-any.whl"
|
||||||
|
expectedPath := filepath.Join(tempDir, expectedFilename)
|
||||||
|
|
||||||
outname, err := PatchWheel(ctx, prebuiltWheel, tempDir)
|
outname, err := PatchWheel(ctx, prebuiltWheel, tempDir)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, expectedPath, outname)
|
||||||
|
|
||||||
_, err = os.Stat(outname)
|
_, err = os.Stat(outname)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -198,10 +208,8 @@ func TestPrebuilt(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer archive.Close()
|
defer archive.Close()
|
||||||
|
|
||||||
// Extract wheel info to determine the dist-info directory name
|
// With fixed time, we know the exact dist-info directory name
|
||||||
wheelInfo, err := ParseWheelFilename(filepath.Base(outname))
|
distInfoPrefix := "my_test_code-" + expectedVersion + ".dist-info/"
|
||||||
require.NoError(t, err)
|
|
||||||
distInfoPrefix := wheelInfo.Distribution + "-" + wheelInfo.Version + ".dist-info/"
|
|
||||||
|
|
||||||
// Find METADATA and RECORD files
|
// Find METADATA and RECORD files
|
||||||
var metadataContent, recordContent []byte
|
var metadataContent, recordContent []byte
|
||||||
|
@ -223,7 +231,7 @@ func TestPrebuilt(t *testing.T) {
|
||||||
|
|
||||||
// Verify METADATA contains the expected version
|
// Verify METADATA contains the expected version
|
||||||
require.NotNil(t, metadataContent, "METADATA file not found in wheel")
|
require.NotNil(t, metadataContent, "METADATA file not found in wheel")
|
||||||
assert.Contains(t, string(metadataContent), "Version: "+wheelInfo.Version)
|
assert.Contains(t, string(metadataContent), "Version: "+expectedVersion)
|
||||||
|
|
||||||
// Verify RECORD contains entries with the correct dist-info prefix
|
// Verify RECORD contains entries with the correct dist-info prefix
|
||||||
require.NotNil(t, recordContent, "RECORD file not found in wheel")
|
require.NotNil(t, recordContent, "RECORD file not found in wheel")
|
||||||
|
|
Loading…
Reference in New Issue