If you need some test instructions, such as assert
, require
, mock
and suite
, you can use this package to assist you in testing: github.com/stretchr/testify
. More usage methods can be found in Instructions.
From the plugin development and Log Printing, you can see that the ilogtail.Context
interface contains the meta configuration information of iLogtail, so Mock Context and Mock Collector are provided for unit testing.
import (
"github.com/stretchr/testify/assert"
"github.com/alibaba/ilogtail/pkg/pipeline"
"github.com/alibaba/ilogtail/plugins/test"
"github.com/alibaba/ilogtail/plugins/test/mock"
"testing"
)
func TestInputSystem_CollectOpenFD(t *testing.T) {
cxt := mock.NewEmptyContext("project", "store", "config")
p := pipeline.MetricInputs["metric_system_v2"]().(*InputSystem)
_, err := p.Init(cxt)
assert.NoError(t, err, "cannot init the mock process plugin: %v", err)
c := &test.MockMetricCollector{}
p.CollectOpenFD(c)
assert.Equal(t, 2, len(c.Logs))
m := make(map[string]string)
for _, log := range c.Logs {
for _, content := range log.Contents {
if content.Key == "__name__" {
m[content.Value] = "exist"
}
}
}
assert.NotEqual(t, "", m["fd_allocated"])
assert.NotEqual(t, "", m["fd_max"])
}
If you need logs to verify the specific behavior of the plugin, you can refer to the part named "Read log content[Advanced]".
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )