-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact_repo_test.go
68 lines (62 loc) · 1.71 KB
/
artifact_repo_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//go:build manual
// Manual because it assumes it can connect to an MLFlow server.
// To run this test, you need to set the following environment variables:
// MLFLOW_TRACKING_URI: the URI of the MLFlow server.
package mlflow
import (
"fmt"
"log"
"os"
"path/filepath"
"testing"
)
func TestLogArtifact(t *testing.T) {
run, err := ActiveRunFromEnv("/Shared/test", log.Default())
if err != nil {
t.Fatal(err.Error())
}
fmt.Println("Run ID", run.ID())
artifactDir := t.TempDir()
f, err := os.OpenFile(filepath.Join(artifactDir, "a.txt"), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
t.Fatal(err.Error())
}
if _, err = f.WriteString("Hello, world!"); err != nil {
t.Fatal(err.Error())
}
if err = f.Close(); err != nil {
t.Fatal(err.Error())
}
if err = os.Mkdir(filepath.Join(artifactDir, "subdir"), 0755); err != nil {
t.Fatal(err.Error())
}
f, err = os.OpenFile(filepath.Join(artifactDir, "subdir", "b.txt"), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
t.Fatal(err.Error())
}
if _, err = f.WriteString("Hello, world!"); err != nil {
t.Fatal(err.Error())
}
if err = f.Close(); err != nil {
t.Fatal(err.Error())
}
f, err = os.OpenFile(filepath.Join(artifactDir, "empty.txt"), os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
t.Fatal(err.Error())
}
if err = f.Close(); err != nil {
t.Fatal(err.Error())
}
if err = run.LogArtifact(artifactDir, ""); err != nil {
t.Fatal(err.Error())
}
// Now relative path
if err = os.Chdir(artifactDir); err != nil {
t.Fatal(err.Error())
}
if err = run.LogArtifact("subdir", ""); err != nil {
t.Fatal(err.Error())
}
fmt.Println("Check the artifacts at ", run.UIURL())
fmt.Printf("They should contain %s and subdir", filepath.Base(artifactDir))
}