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
|
package sls
import (
"testing"
)
func TestLogtailConfigs(t *testing.T) {
p := DefaultProject(t)
_, err := p.ListConfig(0, 100)
if err != nil {
t.Fatalf("error list logtail configs: %v", err)
}
}
func TestCreateLogtailConfig(t *testing.T) {
p := DefaultProject(t)
name := "logtail-test"
logtailConfig := &LogtailConfig{
Name: name,
InputType: "file",
InputDetail: LogtailInput{
LogType: "common_reg_log",
LogPath: "/abc",
FilePattern: "*.log",
LocalStorage: false,
TimeFormat: "",
LogBeginRegex: ".*",
Regex: "(.*)",
Key: []string{"content"},
FilterKey: []string{"content"},
FilterRegex: []string{".*"},
TopicFormat: "none",
},
OutputType: "LogService",
Sample: "sample",
OutputDetail: LogtailOutput{
LogstoreName: TestLogstoreName,
},
}
_, err := p.GetConfig(logtailConfig.Name)
if err != nil {
if e, ok := err.(*Error); ok && e.Code == "ConfigNotExist" {
if err := p.CreateConfig(logtailConfig); err != nil {
t.Fatalf("error create logtail config: %v", err)
}
} else {
t.Fatalf("Get config error: %v", err)
}
}
if err := p.DeleteConfig(name); err != nil {
t.Fatalf("error delete logtail config: %v", err)
}
}
|