-
Notifications
You must be signed in to change notification settings - Fork 4
/
artifact_test.go
97 lines (80 loc) · 2.43 KB
/
artifact_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package limacharlie
import (
"io"
"testing"
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func TestArtifactUpload(t *testing.T) {
a := assert.New(t)
org := getTestOrgFromEnv(a)
// create ingestion key
resp, _ := org.SetIngestionKeys("__test_key")
ingestionKey := resp["key"]
testName := uuid.NewString()
testData := []byte("thisisatestartifactthisisatestartifactthisisatestartifactthisisatestartifactthisisatestartifactthisisatestartifact")
// Tweak the artifact part size to make sure we test the multipart upload.
maxUploadFilePartSize = 15
artifactID := uuid.New().String()
a.NoError(org.CreateArtifactFromBytes(testName, testData, "txt", artifactID, 1, ingestionKey.(string)))
// delete ingestion key
resp, _ = org.DelIngestionKeys("__test_key")
// Download the artifact to make sure it's there.
r, err := org.ExportArtifact(artifactID, time.Now().Add(1*time.Minute))
if err != nil {
t.Fatal(err)
}
b, err := io.ReadAll(r)
a.NoError(err)
if string(b) != string(testData) {
t.Fatalf("artifact data mismatch: %s != %s", string(b), string(testData))
}
}
func TestLoggingAddDelete(t *testing.T) {
a := assert.New(t)
org := getTestOrgFromEnv(a)
unsubReplicantCB, err := findUnsubscribeReplicantCallback(org, "logging")
a.NoError(err)
if unsubReplicantCB != nil {
defer unsubReplicantCB()
}
artifactsRules, err := org.ArtifactsRules()
a.NoError(err)
artifactsRulesStartCount := len(artifactsRules)
a.NoError(org.ArtifactRuleAdd("test-rule", ArtifactRule{
IsIgnoreCert: true,
IsDeleteAfter: true,
DaysRetentions: 90,
Patterns: []string{"/var/log.log", "/home/user"},
Filters: ArtifactRuleFilter{
Tags: []string{"test-tag0"},
Platforms: []string{"windows", "chrome"},
},
}))
artifactsRules, err = org.ArtifactsRules()
a.NoError(err)
a.Equal(artifactsRulesStartCount+1, len(artifactsRules))
a.NoError(org.ArtifactRuleDelete("test-rule"))
artifactsRules, err = org.ArtifactsRules()
a.NoError(err)
a.Equal(artifactsRulesStartCount, len(artifactsRules))
}
// func TestArtifactExport(t *testing.T) {
// o, err := NewOrganizationFromClientOptions(ClientOptions{
// OID: "",
// APIKey: "",
// }, nil)
// if err != nil {
// panic(err)
// }
// r, err := o.ExportArtifact("", time.Now().Add(1*time.Minute))
// if err != nil {
// panic(err)
// }
// b, err := io.ReadAll(r)
// if err != nil {
// panic(err)
// }
// panic(fmt.Sprintf("%x", sha256.Sum256(b)))
// }