import ( "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/assert" ) func TestPlugin_Write_NoFields(t *testing.T) { plugin := myPlugin{} acc := testutil.Accumulator{} plugin.Write(acc) assert.Equal(t, 0, acc.NFields()) }
import ( "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/assert" ) func TestPlugin_Write_WithFields(t *testing.T) { plugin := myPlugin{} acc := testutil.Accumulator{} plugin.Write(acc) assert.Equal(t, 3, acc.NFields()) }In this example, we are testing a plugin that writes three fields. We create a test Accumulator and call the Write method on the plugin, passing in the accumulator. We then use the NFields method on the accumulator to verify that three fields were written by the plugin.