mirror of https://github.com/databricks/cli.git
feat: Implement wheel METADATA and RECORD file verification in test
This commit is contained in:
parent
130ed8b78b
commit
e7af1a606d
|
@ -1,8 +1,10 @@
|
||||||
package patchwheel
|
package patchwheel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"archive/zip"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -189,11 +191,42 @@ func TestPrebuilt(t *testing.T) {
|
||||||
_, err = os.Stat(outname)
|
_, err = os.Stat(outname)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// XXX unpack METADATA and RECORD
|
// Verify the contents of the patched wheel
|
||||||
// AI TODO:
|
archive, err := zip.OpenReader(outname)
|
||||||
// - read zip archive outname
|
require.NoError(t, err)
|
||||||
// - find location of METADATA and RECORD files
|
defer archive.Close()
|
||||||
// - compare contents of METADATA and RECORD with predefined strings
|
|
||||||
|
// Extract wheel info to determine the dist-info directory name
|
||||||
|
wheelInfo, err := ParseWheelFilename(filepath.Base(outname))
|
||||||
|
require.NoError(t, err)
|
||||||
|
distInfoPrefix := wheelInfo.Distribution + "-" + wheelInfo.Version + ".dist-info/"
|
||||||
|
|
||||||
|
// Find METADATA and RECORD files
|
||||||
|
var metadataContent, recordContent []byte
|
||||||
|
for _, f := range archive.File {
|
||||||
|
if f.Name == distInfoPrefix+"METADATA" {
|
||||||
|
rc, err := f.Open()
|
||||||
|
require.NoError(t, err)
|
||||||
|
metadataContent, err = io.ReadAll(rc)
|
||||||
|
rc.Close()
|
||||||
|
require.NoError(t, err)
|
||||||
|
} else if f.Name == distInfoPrefix+"RECORD" {
|
||||||
|
rc, err := f.Open()
|
||||||
|
require.NoError(t, err)
|
||||||
|
recordContent, err = io.ReadAll(rc)
|
||||||
|
rc.Close()
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify METADATA contains the expected version
|
||||||
|
require.NotNil(t, metadataContent, "METADATA file not found in wheel")
|
||||||
|
assert.Contains(t, string(metadataContent), "Version: "+wheelInfo.Version)
|
||||||
|
|
||||||
|
// Verify RECORD contains entries with the correct dist-info prefix
|
||||||
|
require.NotNil(t, recordContent, "RECORD file not found in wheel")
|
||||||
|
assert.Contains(t, string(recordContent), distInfoPrefix+"METADATA")
|
||||||
|
assert.Contains(t, string(recordContent), distInfoPrefix+"RECORD")
|
||||||
}
|
}
|
||||||
|
|
||||||
func errPatchWheel(t *testing.T, name, out string) {
|
func errPatchWheel(t *testing.T, name, out string) {
|
||||||
|
|
Loading…
Reference in New Issue