Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/remote/s3/s3_test.go
4095 views
1
//go:build linux
2
3
package s3
4
5
import (
6
"testing"
7
"time"
8
9
"github.com/prometheus/client_golang/prometheus"
10
11
"github.com/grafana/agent/component"
12
"github.com/stretchr/testify/require"
13
)
14
15
func TestCorrectBucket(t *testing.T) {
16
o := component.Options{
17
ID: "t1",
18
OnStateChange: func(_ component.Exports) {},
19
Registerer: prometheus.NewRegistry(),
20
}
21
s3File, err := New(o,
22
Arguments{
23
Path: "s3://bucket/file",
24
PollFrequency: 30 * time.Second,
25
IsSecret: false,
26
})
27
require.NoError(t, err)
28
require.NotNil(t, s3File)
29
}
30
31
func TestPathBucketAndFileParsing(t *testing.T) {
32
// Path without parent directory
33
pathWithoutParentDir := "s3://bucket/file"
34
bucket, file := getPathBucketAndFile(pathWithoutParentDir)
35
require.Equal(t, "bucket", bucket)
36
require.Equal(t, "file", file)
37
38
// Path with parent directory
39
pathWithParentDir := "s3://bucket/parent/file"
40
bucket, file = getPathBucketAndFile(pathWithParentDir)
41
require.Equal(t, "bucket", bucket)
42
require.Equal(t, "parent/file", file)
43
}
44
45