github.com/yandex/pandora@v0.5.32/tests/acceptance/dummy_test.go (about)

     1  package acceptance
     2  
     3  import (
     4  	"context"
     5  	"net/http/httptest"
     6  	"testing"
     7  
     8  	"github.com/spf13/afero"
     9  	"github.com/stretchr/testify/suite"
    10  	"github.com/yandex/pandora/core/engine"
    11  	"github.com/yandex/pandora/lib/testutil"
    12  	"go.uber.org/zap"
    13  )
    14  
    15  func TestDummyGunSuite(t *testing.T) {
    16  	suite.Run(t, new(DummyGunSuite))
    17  }
    18  
    19  type DummyGunSuite struct {
    20  	suite.Suite
    21  	fs      afero.Fs
    22  	log     *zap.Logger
    23  	metrics engine.Metrics
    24  }
    25  
    26  func (s *DummyGunSuite) SetupSuite() {
    27  	s.fs = afero.NewOsFs()
    28  	testOnce.Do(importDependencies(s.fs))
    29  
    30  	s.log = testutil.NewNullLogger()
    31  	s.metrics = engine.NewMetrics("dummy_suite")
    32  }
    33  
    34  func (s *DummyGunSuite) Test_Shoot() {
    35  	tests := []struct {
    36  		name           string
    37  		filecfg        string
    38  		isTLS          bool
    39  		preStartSrv    func(srv *httptest.Server)
    40  		wantErrContain string
    41  		wantCnt        int
    42  	}{
    43  		{
    44  			name:    "dummy",
    45  			filecfg: "testdata/dummy/dummy.yaml",
    46  			wantCnt: 6,
    47  		},
    48  	}
    49  	for _, tt := range tests {
    50  		s.Run(tt.name, func() {
    51  
    52  			conf := parseConfigFile(s.T(), tt.filecfg, "")
    53  			s.Require().Equal(1, len(conf.Engine.Pools))
    54  			aggr := &aggregator{}
    55  			conf.Engine.Pools[0].Aggregator = aggr
    56  			pandora := engine.New(s.log, s.metrics, conf.Engine)
    57  
    58  			err := pandora.Run(context.Background())
    59  			if tt.wantErrContain != "" {
    60  				s.Require().Error(err)
    61  				s.Require().Contains(err.Error(), tt.wantErrContain)
    62  				return
    63  			}
    64  			s.Require().NoError(err)
    65  			s.Require().Equal(int64(tt.wantCnt), int64(len(aggr.samples)))
    66  		})
    67  	}
    68  }