diff --git a/.mapping.json b/.mapping.json index af6e175ba..78b840c0a 100644 --- a/.mapping.json +++ b/.mapping.json @@ -29,8 +29,6 @@ "LICENSE":"load/projects/pandora/LICENSE", "Makefile":"load/projects/pandora/Makefile", "README.md":"load/projects/pandora/README.md", - "acceptance_tests/acceptance_suite_test.go":"load/projects/pandora/acceptance_tests/acceptance_suite_test.go", - "acceptance_tests/http_test.go":"load/projects/pandora/acceptance_tests/http_test.go", "cli/cli.go":"load/projects/pandora/cli/cli.go", "cli/expvar.go":"load/projects/pandora/cli/expvar.go", "components/grpc/import/import.go":"load/projects/pandora/components/grpc/import/import.go", @@ -52,7 +50,6 @@ "components/guns/http/http_test.go":"load/projects/pandora/components/guns/http/http_test.go", "components/guns/http/mock_client_test.go":"load/projects/pandora/components/guns/http/mock_client_test.go", "components/guns/http/mocks/ammo.go":"load/projects/pandora/components/guns/http/mocks/ammo.go", - "components/guns/http/phttp_suite_test.go":"load/projects/pandora/components/guns/http/phttp_suite_test.go", "components/guns/http/trace.go":"load/projects/pandora/components/guns/http/trace.go", "components/guns/http_scenario/ammo.go":"load/projects/pandora/components/guns/http_scenario/ammo.go", "components/guns/http_scenario/client.go":"load/projects/pandora/components/guns/http_scenario/client.go", @@ -159,7 +156,6 @@ "core/aggregator/mocks/sample_encoder.go":"load/projects/pandora/core/aggregator/mocks/sample_encoder.go", "core/aggregator/netsample/aggregator.go":"load/projects/pandora/core/aggregator/netsample/aggregator.go", "core/aggregator/netsample/mock_aggregator.go":"load/projects/pandora/core/aggregator/netsample/mock_aggregator.go", - "core/aggregator/netsample/netsample_suite_test.go":"load/projects/pandora/core/aggregator/netsample/netsample_suite_test.go", "core/aggregator/netsample/phout.go":"load/projects/pandora/core/aggregator/netsample/phout.go", "core/aggregator/netsample/phout_test.go":"load/projects/pandora/core/aggregator/netsample/phout_test.go", "core/aggregator/netsample/sample.go":"load/projects/pandora/core/aggregator/netsample/sample.go", @@ -203,7 +199,7 @@ "core/engine/instance.go":"load/projects/pandora/core/engine/instance.go", "core/engine/instance_test.go":"load/projects/pandora/core/engine/instance_test.go", "core/import/import.go":"load/projects/pandora/core/import/import.go", - "core/import/import_suite_test.go":"load/projects/pandora/core/import/import_suite_test.go", + "core/import/import_test.go":"load/projects/pandora/core/import/import_test.go", "core/mocks/aggregator.go":"load/projects/pandora/core/mocks/aggregator.go", "core/mocks/borrowed_sample.go":"load/projects/pandora/core/mocks/borrowed_sample.go", "core/mocks/data_sink.go":"load/projects/pandora/core/mocks/data_sink.go", @@ -217,7 +213,6 @@ "core/plugin/doc.go":"load/projects/pandora/core/plugin/doc.go", "core/plugin/example_test.go":"load/projects/pandora/core/plugin/example_test.go", "core/plugin/plugin.go":"load/projects/pandora/core/plugin/plugin.go", - "core/plugin/plugin_suite_test.go":"load/projects/pandora/core/plugin/plugin_suite_test.go", "core/plugin/plugin_test.go":"load/projects/pandora/core/plugin/plugin_test.go", "core/plugin/pluginconfig/hooks.go":"load/projects/pandora/core/plugin/pluginconfig/hooks.go", "core/plugin/pluginconfig/hooks_test.go":"load/projects/pandora/core/plugin/pluginconfig/hooks_test.go", @@ -231,7 +226,6 @@ "core/provider/json_test.go":"load/projects/pandora/core/provider/json_test.go", "core/provider/num.go":"load/projects/pandora/core/provider/num.go", "core/provider/num_test.go":"load/projects/pandora/core/provider/num_test.go", - "core/provider/provider_suite_test.go":"load/projects/pandora/core/provider/provider_suite_test.go", "core/provider/queue.go":"load/projects/pandora/core/provider/queue.go", "core/register/register.go":"load/projects/pandora/core/register/register.go", "core/schedule/composite.go":"load/projects/pandora/core/schedule/composite.go", @@ -241,7 +235,7 @@ "core/schedule/instance_step.go":"load/projects/pandora/core/schedule/instance_step.go", "core/schedule/line.go":"load/projects/pandora/core/schedule/line.go", "core/schedule/once.go":"load/projects/pandora/core/schedule/once.go", - "core/schedule/schedule_suite_test.go":"load/projects/pandora/core/schedule/schedule_suite_test.go", + "core/schedule/schedule_test.go":"load/projects/pandora/core/schedule/schedule_test.go", "core/schedule/start_sync.go":"load/projects/pandora/core/schedule/start_sync.go", "core/schedule/step.go":"load/projects/pandora/core/schedule/step.go", "core/schedule/unlilmited.go":"load/projects/pandora/core/schedule/unlilmited.go", @@ -319,10 +313,7 @@ "lib/confutil/property_var_resolver.go":"load/projects/pandora/lib/confutil/property_var_resolver.go", "lib/confutil/property_var_resolver_test.go":"load/projects/pandora/lib/confutil/property_var_resolver_test.go", "lib/errutil/errutil.go":"load/projects/pandora/lib/errutil/errutil.go", - "lib/errutil/errutil_suite_test.go":"load/projects/pandora/lib/errutil/errutil_suite_test.go", "lib/errutil/errutil_test.go":"load/projects/pandora/lib/errutil/errutil_test.go", - "lib/ginkgoutil/ginkgo.go":"load/projects/pandora/lib/ginkgoutil/ginkgo.go", - "lib/ginkgoutil/matchers.go":"load/projects/pandora/lib/ginkgoutil/matchers.go", "lib/ioutil2/closer.go":"load/projects/pandora/lib/ioutil2/closer.go", "lib/ioutil2/funcs.go":"load/projects/pandora/lib/ioutil2/funcs.go", "lib/ioutil2/io_mocks_test.go":"load/projects/pandora/lib/ioutil2/io_mocks_test.go", @@ -343,7 +334,7 @@ "lib/netutil/mocks/conn.go":"load/projects/pandora/lib/netutil/mocks/conn.go", "lib/netutil/mocks/dialer.go":"load/projects/pandora/lib/netutil/mocks/dialer.go", "lib/netutil/mocks/dns_cache.go":"load/projects/pandora/lib/netutil/mocks/dns_cache.go", - "lib/netutil/netutil_suite_test.go":"load/projects/pandora/lib/netutil/netutil_suite_test.go", + "lib/netutil/netutil_test.go":"load/projects/pandora/lib/netutil/netutil_test.go", "lib/netutil/validator.go":"load/projects/pandora/lib/netutil/validator.go", "lib/pointer/pointer.go":"load/projects/pandora/lib/pointer/pointer.go", "lib/str/format.go":"load/projects/pandora/lib/str/format.go", @@ -360,7 +351,6 @@ "lib/testutil/util.go":"load/projects/pandora/lib/testutil/util.go", "lib/zaputil/stack_extract_core.go":"load/projects/pandora/lib/zaputil/stack_extract_core.go", "lib/zaputil/stack_extract_core_test.go":"load/projects/pandora/lib/zaputil/stack_extract_core_test.go", - "lib/zaputil/zaputil_suite_test.go":"load/projects/pandora/lib/zaputil/zaputil_suite_test.go", "main.go":"load/projects/pandora/main.go", "script/checkfmt.sh":"load/projects/pandora/script/checkfmt.sh", "script/coverage.sh":"load/projects/pandora/script/coverage.sh", diff --git a/acceptance_tests/acceptance_suite_test.go b/acceptance_tests/acceptance_suite_test.go deleted file mode 100644 index ac88799c7..000000000 --- a/acceptance_tests/acceptance_suite_test.go +++ /dev/null @@ -1,186 +0,0 @@ -package acceptance - -import ( - "encoding/json" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "testing" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/onsi/gomega/gbytes" - "github.com/onsi/gomega/gexec" - "github.com/yandex/pandora/lib/ginkgoutil" - "github.com/yandex/pandora/lib/tag" - "go.uber.org/zap" - "gopkg.in/yaml.v2" -) - -var pandoraBin string - -func TestAcceptanceTests(t *testing.T) { - ginkgoutil.SetupSuite() - var args []string - if tag.Race { - zap.L().Debug("Building with race detector") - args = append(args, "-race") - } - if tag.Debug { - zap.L().Debug("Building with debug tag") - args = append(args, "-tags", "debug") - } - var err error - pandoraBin, err = gexec.Build("github.com/yandex/pandora", args...) - if err != nil { - t.Fatal(err) - } - defer gexec.CleanupBuildArtifacts() - RunSpecs(t, "AcceptanceTests Suite") -} - -type TestConfig struct { - // Default way to pass config to pandora. - PandoraConfig - // RawConfig overrides Pandora. - RawConfig string - ConfigName string // Without extension. "load" by default. - UseJSON bool // Using YAML by default. - CmdArgs []string // Nothing by default. - Files map[string]string // Extra files to put in dir. Ammo, etc. -} - -func NewTestConfig() *TestConfig { - return &TestConfig{ - PandoraConfig: PandoraConfig{ - Pool: []*InstancePoolConfig{NewInstansePoolConfig()}, - }, - Files: map[string]string{}, - } -} - -type PandoraConfig struct { - Pool []*InstancePoolConfig `yaml:"pools" json:"pools"` - LogConfig `yaml:"log,omitempty" json:"log,omitempty"` - MonitoringConfig `yaml:"monitoring,omitempty" json:"monitoring,omitempty"` -} - -type LogConfig struct { - Level string `yaml:"level,omitempty" json:"level,omitempty"` - File string `yaml:"file,omitempty" json:"file,omitempty"` -} - -type MonitoringConfig struct { - Expvar *expvarConfig `yaml:"Expvar"` - CPUProfile *cpuprofileConfig `yaml:"CPUProfile"` - MemProfile *memprofileConfig `yaml:"MemProfile"` -} - -type expvarConfig struct { - Enabled bool `yaml:"enabled" json:"enabled"` - Port int `yaml:"port" json:"port"` -} - -type cpuprofileConfig struct { - Enabled bool `yaml:"enabled" json:"enabled"` - File string `yaml:"file" json:"file"` -} - -type memprofileConfig struct { - Enabled bool `yaml:"enabled" json:"enabled"` - File string `yaml:"file" json:"file"` -} - -func (pc *PandoraConfig) Append(ipc *InstancePoolConfig) { - pc.Pool = append(pc.Pool, ipc) -} - -func NewInstansePoolConfig() *InstancePoolConfig { - return &InstancePoolConfig{ - Provider: map[string]interface{}{}, - Aggregator: map[string]interface{}{}, - Gun: map[string]interface{}{}, - RPSSchedule: map[string]interface{}{}, - StartupSchedule: map[string]interface{}{}, - } - -} - -type InstancePoolConfig struct { - ID string - Provider map[string]interface{} `yaml:"ammo" json:"ammo"` - Aggregator map[string]interface{} `yaml:"result" json:"result"` - Gun map[string]interface{} `yaml:"gun" json:"gun"` - RPSPerInstance bool `yaml:"rps-per-instance" json:"rps-per-instance"` - RPSSchedule interface{} `yaml:"rps" json:"rps"` - StartupSchedule interface{} `yaml:"startup" json:"startup"` -} - -type PandoraTester struct { - *gexec.Session - // TestDir is working dir of launched pandora. - // It contains config and ammo files, and will be removed after test execution. - // All files created during a test should created in this dir. - TestDir string - Config *TestConfig -} - -func NewTester(conf *TestConfig) *PandoraTester { - testDir, err := ioutil.TempDir("", "pandora_acceptance_") - Expect(err).ToNot(HaveOccurred()) - if conf.ConfigName == "" { - conf.ConfigName = "load" - } - extension := "yaml" - if conf.UseJSON { - extension = "json" - } - var confData []byte - - if conf.RawConfig != "" { - confData = []byte(conf.RawConfig) - } else { - if conf.UseJSON { - confData, err = json.Marshal(conf.PandoraConfig) - } else { - confData, err = yaml.Marshal(conf.PandoraConfig) - } - Expect(err).ToNot(HaveOccurred()) - } - confAbsName := filepath.Join(testDir, conf.ConfigName+"."+extension) - err = ioutil.WriteFile(confAbsName, confData, 0644) - Expect(err).ToNot(HaveOccurred()) - - for file, data := range conf.Files { - fileAbsName := filepath.Join(testDir, file) - err = ioutil.WriteFile(fileAbsName, []byte(data), 0644) - Expect(err).ToNot(HaveOccurred()) - } - - command := exec.Command(pandoraBin, conf.CmdArgs...) - command.Dir = testDir - session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) - Expect(err).ToNot(HaveOccurred()) - - tt := &PandoraTester{ - Session: session, - TestDir: testDir, - Config: conf, - } - return tt -} - -func (pt *PandoraTester) ShouldSay(pattern string) { - EventuallyWithOffset(1, pt.Out, 3*time.Second).Should(gbytes.Say(pattern)) -} - -func (pt *PandoraTester) ExitCode() int { - return pt.Session.Wait(5).ExitCode() -} - -func (pt *PandoraTester) Close() { - pt.Terminate() - _ = os.RemoveAll(pt.TestDir) -} diff --git a/acceptance_tests/http_test.go b/acceptance_tests/http_test.go deleted file mode 100644 index fea9dc757..000000000 --- a/acceptance_tests/http_test.go +++ /dev/null @@ -1,137 +0,0 @@ -package acceptance - -import ( - "net/http" - "net/http/httptest" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "go.uber.org/atomic" - "golang.org/x/net/http2" -) - -var _ = Describe("http", func() { - var ( - server *httptest.Server - conf *TestConfig - tester *PandoraTester - ) - ServerEndpoint := func() string { - Expect(server).NotTo(BeNil()) - return server.Listener.Addr().String() - } - BeforeEach(func() { - conf = NewTestConfig() - tester = nil - }) - JustBeforeEach(func() { - if server != nil { - Expect(server.URL).NotTo(BeEmpty(), "Please start server manually") - } - tester = NewTester(conf) - }) - AfterEach(func() { - tester.Close() - if server != nil { - server.Close() - server = nil - } - }) - - Context("uri ammo", func() { - var ( - requetsCount atomic.Int64 // Request served by test server. - gunConfig map[string]interface{} // gunConfig config section. - ) - const ( - Requests = 4 - Instances = 2 - OutFile = "out.log" - ) - BeforeEach(func() { - requetsCount.Store(0) - server = httptest.NewUnstartedServer(http.HandlerFunc( - func(rw http.ResponseWriter, req *http.Request) { - requetsCount.Inc() - rw.WriteHeader(http.StatusOK) - })) - - conf.Pool[0].Gun = map[string]interface{}{ - // Set type in test. - "target": ServerEndpoint(), - } - const ammoFile = "ammo.uri" - conf.Pool[0].Provider = map[string]interface{}{ - "type": "uri", - "file": ammoFile, - } - conf.Files[ammoFile] = "/" - conf.Pool[0].Aggregator = map[string]interface{}{ - "type": "phout", - "destination": OutFile, - } - conf.Pool[0].RPSSchedule = []map[string]interface{}{ - {"type": "once", "times": Requests / 2}, - {"type": "const", "ops": Requests, "duration": "0.5s"}, - } - conf.Pool[0].StartupSchedule = []map[string]interface{}{ - {"type": "once", "times": Instances}, - } - gunConfig = conf.Pool[0].Gun - conf.Level = "debug" - }) - itOk := func() { - It("ok", func() { - exitCode := tester.ExitCode() - Expect(exitCode).To(BeZero(), "Pandora finish execution with non zero code") - Expect(requetsCount.Load()).To(BeEquivalentTo(Requests)) - // TODO(skipor): parse and check phout output - }) - } - - Context("http", func() { - BeforeEach(func() { - server.Start() - gunConfig["type"] = "http" - }) - itOk() - }) - - Context("https", func() { - BeforeEach(func() { - server.StartTLS() - gunConfig["type"] = "http" - gunConfig["ssl"] = true - }) - itOk() - }) - - Context("http2", func() { - Context("target support HTTP/2", func() { - BeforeEach(func() { - startHTTP2(server) - gunConfig["type"] = "http2" - }) - itOk() - }) - Context("target DOESN'T support HTTP/2", func() { - BeforeEach(func() { - server.StartTLS() - gunConfig["type"] = "http2" - }) - It("ok", func() { - exitCode := tester.ExitCode() - Expect(exitCode).NotTo(BeZero(), "Pandora should fail") - }) - - }) - }) - - }) -}) - -func startHTTP2(server *httptest.Server) { - _ = http2.ConfigureServer(server.Config, nil) - server.TLS = server.Config.TLSConfig - server.StartTLS() -} diff --git a/components/guns/http/base_test.go b/components/guns/http/base_test.go index 3d5deb136..cb9093aa4 100644 --- a/components/guns/http/base_test.go +++ b/components/guns/http/base_test.go @@ -13,202 +13,304 @@ import ( "net/http/httptest" "net/url" "strings" + "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" - . "github.com/onsi/gomega" - "github.com/stretchr/testify/mock" + "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" ammomock "github.com/yandex/pandora/components/guns/http/mocks" "github.com/yandex/pandora/core" "github.com/yandex/pandora/core/aggregator/netsample" "github.com/yandex/pandora/core/coretest" - "github.com/yandex/pandora/lib/ginkgoutil" + "github.com/yandex/pandora/core/engine" + "github.com/yandex/pandora/lib/monitoring" + "github.com/yandex/pandora/lib/testutil" "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) -func testDeps() core.GunDeps { - return core.GunDeps{ - Log: ginkgoutil.NewLogger(), - Ctx: context.Background(), +func newLogger() *zap.Logger { + zapConf := zap.NewDevelopmentConfig() + zapConf.Level.SetLevel(zapcore.DebugLevel) + log, err := zapConf.Build(zap.AddCaller()) + if err != nil { + zap.L().Fatal("Logger build failed", zap.Error(err)) } + return log } -var _ = Describe("BaseGun", func() { +func newEngineMetrics(prefix string) engine.Metrics { + return engine.Metrics{ + Request: monitoring.NewCounter(prefix + "_Requests"), + Response: monitoring.NewCounter(prefix + "_Responses"), + InstanceStart: monitoring.NewCounter(prefix + "_UsersStarted"), + InstanceFinish: monitoring.NewCounter(prefix + "_UsersFinished"), + } +} - var ( - base BaseGun - ) - BeforeEach(func() { - base = BaseGun{Config: DefaultBaseGunConfig()} - }) +func TestGunSuite(t *testing.T) { + suite.Run(t, new(BaseGunSuite)) +} + +type BaseGunSuite struct { + suite.Suite + fs afero.Fs + log *zap.Logger + metrics engine.Metrics + base BaseGun + gunDeps core.GunDeps +} - Context("BindResultTo", func() { - It("nil panics", func() { - Expect(func() { - _ = base.Bind(nil, testDeps()) - }).To(Panic()) +func (s *BaseGunSuite) SetupSuite() { + s.log = testutil.NewLogger() + s.metrics = newEngineMetrics("http_suite") +} + +func (s *BaseGunSuite) SetupTest() { + s.base = BaseGun{Config: DefaultBaseGunConfig()} +} + +func (s *BaseGunSuite) Test_BindResultTo_Panics() { + s.Run("nil panic", func() { + s.Panics(func() { + _ = s.base.Bind(nil, testDeps()) }) - It("second time panics", func() { - res := &netsample.TestAggregator{} - _ = base.Bind(res, testDeps()) - Expect(base.Aggregator).To(Equal(res)) - Expect(func() { - _ = base.Bind(&netsample.TestAggregator{}, testDeps()) - }).To(Panic()) + }) + s.Run("nil panic", func() { + res := &netsample.TestAggregator{} + _ = s.base.Bind(res, testDeps()) + s.Require().Equal(res, s.base.Aggregator) + s.Panics(func() { + _ = s.base.Bind(&netsample.TestAggregator{}, testDeps()) }) }) +} + +type ammoMock struct { + requestCallCnt int + idCallCnt int + isInvalidCallCnt int +} + +func (a *ammoMock) Request() (*http.Request, *netsample.Sample) { + a.requestCallCnt++ + return nil, nil +} + +func (a *ammoMock) ID() uint64 { + a.idCallCnt++ + return 0 +} + +func (a *ammoMock) IsInvalid() bool { + a.isInvalidCallCnt++ + return false +} + +func (s *BaseGunSuite) Test_Shoot_BeforeBindPanics() { + s.base.Do = func(*http.Request) (_ *http.Response, _ error) { + panic("should not be called") + } + am := &ammoMock{} + + s.Panics(func() { + s.base.Shoot(am) + }) +} + +func (s *BaseGunSuite) Test_Shoot() { + var ( + body io.ReadCloser - It("Shoot before bind panics", func() { - base.Do = func(*http.Request) (_ *http.Response, _ error) { - Fail("should not be called") - return + am *ammomock.Ammo + req *http.Request + tag string + res *http.Response + sample *netsample.Sample + results *netsample.TestAggregator + shootErr error + ) + beforeEach := func() { + am = ammomock.NewAmmo(s.T()) + am.On("IsInvalid").Return(false).Maybe() + req = httptest.NewRequest("GET", "/1/2/3/4", nil) + tag = "" + results = &netsample.TestAggregator{} + _ = s.base.Bind(results, testDeps()) + } + + justBeforeEach := func() { + sample = netsample.Acquire(tag) + am.On("Request").Return(req, sample).Maybe() + res = &http.Response{ + StatusCode: http.StatusNotFound, + Body: ioutil.NopCloser(body), + Request: req, } - am := ammomock.NewAmmo(GinkgoT()) - am.On("Request").Return(nil, nil).Run( - func(mock.Arguments) { - Fail("should not be called") - }) - am.On("IsInvalid").Return(false) - Expect(func() { - base.Shoot(am) - }).To(Panic()) - }, 1) - - Context("Shoot", func() { - var ( - body io.ReadCloser - - am *ammomock.Ammo - req *http.Request - tag string - res *http.Response - sample *netsample.Sample - results *netsample.TestAggregator - shootErr error - ) - BeforeEach(func() { - am = ammomock.NewAmmo(GinkgoT()) - am.On("IsInvalid").Return(false) - req = httptest.NewRequest("GET", "/1/2/3/4", nil) - tag = "" - results = &netsample.TestAggregator{} - _ = base.Bind(results, testDeps()) - }) + s.base.Shoot(am) + s.Require().Len(results.Samples, 1) + shootErr = results.Samples[0].Err() + } - JustBeforeEach(func() { - sample = netsample.Acquire(tag) - am.On("Request").Return(req, sample) - res = &http.Response{ - StatusCode: http.StatusNotFound, - Body: ioutil.NopCloser(body), - Request: req, + s.Run("Do ok", func() { + beforeEachDoOk := func() { + body = ioutil.NopCloser(strings.NewReader("aaaaaaa")) + s.base.AnswLog = zap.NewNop() + s.base.Do = func(doReq *http.Request) (*http.Response, error) { + s.Require().Equal(req, doReq) + return res, nil } - base.Shoot(am) - Expect(results.Samples).To(HaveLen(1)) - shootErr = results.Samples[0].Err() + } + s.Run("ammo sample sent to results", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + justBeforeEach() + + s.Assert().Len(results.Samples, 1) + s.Assert().Equal(sample, results.Samples[0]) + s.Assert().Equal("__EMPTY__", sample.Tags()) + s.Assert().Equal(res.StatusCode, sample.ProtoCode()) + _ = shootErr }) - Context("Do ok", func() { - BeforeEach(func() { - body = ioutil.NopCloser(strings.NewReader("aaaaaaa")) - base.AnswLog = zap.NewNop() - base.Do = func(doReq *http.Request) (*http.Response, error) { - Expect(doReq).To(Equal(req)) - return res, nil - } - }) + s.Run("body read well", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + justBeforeEach() - It("ammo sample sent to results", func() { - Expect(results.Samples).To(HaveLen(1)) - Expect(results.Samples[0]).To(Equal(sample)) - Expect(sample.Tags()).To(Equal("__EMPTY__")) - Expect(sample.ProtoCode()).To(Equal(res.StatusCode)) - }) - It("body read well", func() { - Expect(shootErr).To(BeNil()) - _, err := body.Read([]byte{0}) - Expect(err).To(Equal(io.EOF), "body should be read fully") + s.Assert().NoError(shootErr) + _, err := body.Read([]byte{0}) + s.Assert().ErrorIs(err, io.EOF, "body should be read fully") + }) + + s.Run("autotag options is set", func() { + beforeEacAautotag := (func() { s.base.Config.AutoTag.Enabled = true }) + + s.Run("autotagged", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + beforeEacAautotag() + justBeforeEach() + + s.Assert().Equal("/1/2", sample.Tags()) }) - Context("autotag options is set", func() { - BeforeEach(func() { base.Config.AutoTag.Enabled = true }) - It("autotagged", func() { - Expect(sample.Tags()).To(Equal("/1/2")) + s.Run("tag is already set", func() { + const presetTag = "TAG" + beforeEachTagIsAlreadySet := func() { tag = presetTag } + s.Run("no tag added", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + beforeEacAautotag() + beforeEachTagIsAlreadySet() + justBeforeEach() + + s.Assert().Equal(presetTag, sample.Tags()) }) - Context("tag is already set", func() { - const presetTag = "TAG" - BeforeEach(func() { tag = presetTag }) - It("no tag added", func() { - Expect(sample.Tags()).To(Equal(presetTag)) - }) + s.Run("no-tag-only set to false", func() { + beforeEachNoTagOnly := func() { s.base.Config.AutoTag.NoTagOnly = false } + s.Run("autotag added", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + beforeEacAautotag() + beforeEachTagIsAlreadySet() + beforeEachNoTagOnly() + justBeforeEach() - Context("no-tag-only set to false", func() { - BeforeEach(func() { base.Config.AutoTag.NoTagOnly = false }) - It("autotag added", func() { - Expect(sample.Tags()).To(Equal(presetTag + "|/1/2")) - }) + s.Assert().Equal(presetTag+"|/1/2", sample.Tags()) }) }) }) + }) - Context("Connect set", func() { - var connectCalled, doCalled bool - BeforeEach(func() { - base.Connect = func(ctx context.Context) error { - connectCalled = true - return nil - } - oldDo := base.Do - base.Do = func(r *http.Request) (*http.Response, error) { - doCalled = true - return oldDo(r) - } - }) - It("Connect called", func() { - Expect(shootErr).To(BeNil()) - Expect(connectCalled).To(BeTrue()) - Expect(doCalled).To(BeTrue()) - }) + s.Run("Connect set", func() { + var connectCalled, doCalled bool + beforeEachConnectSet := func() { + s.base.Connect = func(ctx context.Context) error { + connectCalled = true + return nil + } + oldDo := s.base.Do + s.base.Do = func(r *http.Request) (*http.Response, error) { + doCalled = true + return oldDo(r) + } + } + s.Run("Connect called", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + beforeEachConnectSet() + justBeforeEach() + + s.Assert().NoError(shootErr) + s.Assert().True(connectCalled) + s.Assert().True(doCalled) }) - Context("Connect failed", func() { - connectErr := errors.New("connect error") - BeforeEach(func() { - base.Connect = func(ctx context.Context) error { - // Connect should report fail in sample itself. - s := netsample.Acquire("") - s.SetErr(connectErr) - results.Report(s) - return connectErr - } - }) - It("Shoot failed", func() { - Expect(shootErr).NotTo(BeNil()) - Expect(shootErr).To(Equal(connectErr)) - }) + }) + s.Run("Connect failed", func() { + connectErr := errors.New("connect error") + beforeEachConnectFailed := func() { + s.base.Connect = func(ctx context.Context) error { + // Connect should report fail in sample itself. + s := netsample.Acquire("") + s.SetErr(connectErr) + results.Report(s) + return connectErr + } + } + s.Run("Shoot failed", func() { + s.SetupTest() + beforeEach() + beforeEachDoOk() + beforeEachConnectFailed() + justBeforeEach() + + s.Assert().Error(shootErr) + s.Assert().ErrorIs(shootErr, connectErr) }) }) }) +} - DescribeTable("autotag", - func(path string, depth int, tag string) { - URL := &url.URL{Path: path} - Expect(autotag(depth, URL)).To(Equal(tag)) - }, - Entry("empty", "", 2, ""), - Entry("root", "/", 2, "/"), - Entry("exact depth", "/1/2", 2, "/1/2"), - Entry("more depth", "/1/2", 3, "/1/2"), - Entry("less depth", "/1/2", 1, "/1"), - ) +func Test_Autotag(t *testing.T) { + tests := []struct { + name string + path string + depth int + tag string + }{ + {"empty", "", 2, ""}, + {"root", "/", 2, "/"}, + {"exact depth", "/1/2", 2, "/1/2"}, + {"more depth", "/1/2", 3, "/1/2"}, + {"less depth", "/1/2", 1, "/1"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + URL := &url.URL{Path: tt.path} + got := autotag(tt.depth, URL) + assert.Equal(t, got, tt.tag) + }) + } +} - It("config decode", func() { - var conf BaseGunConfig - coretest.DecodeAndValidate(` +func Test_ConfigDecode(t *testing.T) { + var conf BaseGunConfig + coretest.DecodeAndValidateT(t, ` auto-tag: enabled: true uri-elements: 3 no-tag-only: false `, &conf) - }) -}) +} + +func testDeps() core.GunDeps { + return core.GunDeps{Log: testutil.NewLogger(), Ctx: context.Background()} +} diff --git a/components/guns/http/connect_test.go b/components/guns/http/connect_test.go index 139779e6d..0f86d74ee 100644 --- a/components/guns/http/connect_test.go +++ b/components/guns/http/connect_test.go @@ -91,7 +91,6 @@ func TestDo(t *testing.T) { } func TestNewConnectGun(t *testing.T) { - origin := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusOK) })) diff --git a/components/guns/http/phttp_suite_test.go b/components/guns/http/phttp_suite_test.go deleted file mode 100644 index 2dc671a62..000000000 --- a/components/guns/http/phttp_suite_test.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2017 Yandex LLC. All rights reserved. -// Use of this source code is governed by a MPL 2.0 -// license that can be found in the LICENSE file. -// Author: Vladimir Skipor - -package phttp - -import ( - "testing" - - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestPhttp(t *testing.T) { - ginkgoutil.RunSuite(t, "HTTP Suite") -} diff --git a/core/aggregator/netsample/netsample_suite_test.go b/core/aggregator/netsample/netsample_suite_test.go deleted file mode 100644 index a243696ba..000000000 --- a/core/aggregator/netsample/netsample_suite_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package netsample - -import ( - "testing" - - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestNetsample(t *testing.T) { - ginkgoutil.RunSuite(t, "Netsample Suite") -} diff --git a/core/aggregator/netsample/phout_test.go b/core/aggregator/netsample/phout_test.go index 33f6a7bea..cc19fd153 100644 --- a/core/aggregator/netsample/phout_test.go +++ b/core/aggregator/netsample/phout_test.go @@ -3,66 +3,70 @@ package netsample import ( "context" "strings" + "testing" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/spf13/afero" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/yandex/pandora/core" ) -var _ = Describe("Phout", func() { +func TestPhout(t *testing.T) { const fileName = "out.txt" - var ( - fs afero.Fs - conf PhoutConfig - testee Aggregator - ctx context.Context - cancel context.CancelFunc - runErr chan error - ) - getOutput := func() string { - data, err := afero.ReadFile(fs, fileName) - Expect(err).NotTo(HaveOccurred()) - return string(data) + + tests := []struct { + name string + resetConf func(cfg *PhoutConfig) + reportCnt int + want string + }{ + { + name: "no id by default", + reportCnt: 2, + want: strings.Repeat(testSampleNoIDPhout+"\n", 2), + }, + { + name: "id option set", + resetConf: func(cfg *PhoutConfig) { + cfg.ID = true + }, + reportCnt: 1, + want: testSamplePhout + "\n", + }, } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + fs := afero.NewMemMapFs() + conf := DefaultPhoutConfig() + conf.Destination = fileName + if tt.resetConf != nil { + tt.resetConf(&conf) + } + ctx, cancel := context.WithCancel(context.Background()) - BeforeEach(func() { - fs = afero.NewMemMapFs() - conf = DefaultPhoutConfig() - conf.Destination = fileName - ctx, cancel = context.WithCancel(context.Background()) - }) - JustBeforeEach(func() { - var err error - testee, err = NewPhout(fs, conf) - Expect(err).NotTo(HaveOccurred()) - runErr = make(chan error) - go func() { - runErr <- testee.Run(ctx, core.AggregatorDeps{}) - }() - }) - It("no id by default", func() { - testee.Report(newTestSample()) - testee.Report(newTestSample()) - cancel() - Expect(<-runErr).NotTo(HaveOccurred()) - Expect(getOutput()).To(Equal(strings.Repeat(testSampleNoIDPhout+"\n", 2))) - }, 1) - Context("id option set", func() { - BeforeEach(func() { - conf.ID = true - }) - It("id printed", func() { - testee.Report(newTestSample()) + var err error + testee, err := NewPhout(fs, conf) + require.NoError(t, err) + runErr := make(chan error) + go func() { + runErr <- testee.Run(ctx, core.AggregatorDeps{}) + }() + + for i := 0; i < tt.reportCnt; i++ { + testee.Report(newTestSample()) + } cancel() - Expect(<-runErr).NotTo(HaveOccurred()) - Expect(getOutput()).To(Equal(testSamplePhout + "\n")) - }, 1) + err = <-runErr + assert.NoError(t, err) - }) + data, err := afero.ReadFile(fs, fileName) + require.NoError(t, err) -}) + assert.Equal(t, tt.want, string(data)) + }) + } +} const ( testSamplePhout = "1484660999.002 tag1|tag2#42 333333 0 0 0 0 0 0 0 13 999" diff --git a/core/coretest/config.go b/core/coretest/config.go index 33204b753..b05c8b11a 100644 --- a/core/coretest/config.go +++ b/core/coretest/config.go @@ -6,19 +6,30 @@ package coretest import ( - "github.com/onsi/gomega" + "strings" + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/require" "github.com/yandex/pandora/core/config" - "github.com/yandex/pandora/lib/ginkgoutil" ) -func Decode(data string, result interface{}) { - conf := ginkgoutil.ParseYAML(data) +func DecodeT(t *testing.T, data string, result interface{}) { + conf := ParseYAML(t, data) err := config.Decode(conf, result) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) + require.NoError(t, err) } -func DecodeAndValidate(data string, result interface{}) { - Decode(data, result) +func DecodeAndValidateT(t *testing.T, data string, result interface{}) { + DecodeT(t, data, result) err := config.Validate(result) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) + require.NoError(t, err) +} + +func ParseYAML(t *testing.T, data string) map[string]interface{} { + v := viper.New() + v.SetConfigType("yaml") + err := v.ReadConfig(strings.NewReader(data)) + require.NoError(t, err) + return v.AllSettings() } diff --git a/core/coretest/schedule.go b/core/coretest/schedule.go index 73d9511d2..7a995ede3 100644 --- a/core/coretest/schedule.go +++ b/core/coretest/schedule.go @@ -6,31 +6,45 @@ package coretest import ( + "testing" "time" - "github.com/onsi/gomega" + "github.com/stretchr/testify/require" "github.com/yandex/pandora/core" ) -func ExpectScheduleNextsStartAt(sched core.Schedule, startAt time.Time, nexts ...time.Duration) { +func ExpectScheduleNextsStartAt(t *testing.T, sched core.Schedule, startAt time.Time, nexts ...time.Duration) { beforeStartLeft := sched.Left() tokensExpected := len(nexts) - 1 // Last next is finish time. - gomega.Expect(beforeStartLeft).To(gomega.Equal(tokensExpected)) + require.Equal(t, tokensExpected, beforeStartLeft) sched.Start(startAt) - actualNexts := DrainScheduleDuration(sched, startAt) - gomega.Expect(actualNexts).To(gomega.Equal(nexts)) + actualNexts := DrainScheduleDuration(t, sched, startAt) + require.Equal(t, nexts, actualNexts) } -func ExpectScheduleNexts(sched core.Schedule, nexts ...time.Duration) { - ExpectScheduleNextsStartAt(sched, time.Now(), nexts...) +func ExpectScheduleNexts(t *testing.T, sched core.Schedule, nexts ...time.Duration) { + ExpectScheduleNextsStartAt(t, sched, time.Now(), nexts...) +} + +func ExpectScheduleNextsStartAtT(t *testing.T, sched core.Schedule, startAt time.Time, nexts ...time.Duration) { + beforeStartLeft := sched.Left() + tokensExpected := len(nexts) - 1 // Last next is finish time. + require.Equal(t, tokensExpected, beforeStartLeft) + sched.Start(startAt) + actualNexts := DrainScheduleDuration(t, sched, startAt) + require.Equal(t, nexts, actualNexts) +} + +func ExpectScheduleNextsT(t *testing.T, sched core.Schedule, nexts ...time.Duration) { + ExpectScheduleNextsStartAtT(t, sched, time.Now(), nexts...) } const drainLimit = 1000000 // DrainSchedule starts schedule and takes all tokens from it. // Returns all tokens and finish time relative to start -func DrainScheduleDuration(sched core.Schedule, startAt time.Time) []time.Duration { - nexts := DrainSchedule(sched) +func DrainScheduleDuration(t *testing.T, sched core.Schedule, startAt time.Time) []time.Duration { + nexts := DrainSchedule(t, sched) durations := make([]time.Duration, len(nexts)) for i, next := range nexts { durations[i] = next.Sub(startAt) @@ -40,18 +54,18 @@ func DrainScheduleDuration(sched core.Schedule, startAt time.Time) []time.Durati // DrainSchedule takes all tokens from passed schedule. // Returns all tokens and finish time. -func DrainSchedule(sched core.Schedule) []time.Time { +func DrainSchedule(t *testing.T, sched core.Schedule) []time.Time { expectedLeft := sched.Left() var nexts []time.Time for len(nexts) < drainLimit { next, ok := sched.Next() nexts = append(nexts, next) if !ok { - gomega.Expect(sched.Left()).To(gomega.Equal(0)) + require.Equal(t, 0, sched.Left()) return nexts } expectedLeft-- - gomega.Expect(sched.Left()).To(gomega.Equal(expectedLeft)) + require.Equal(t, expectedLeft, sched.Left()) } panic("drain limit reached") } diff --git a/core/import/import_suite_test.go b/core/import/import_test.go similarity index 84% rename from core/import/import_suite_test.go rename to core/import/import_test.go index a83785439..49a16ec9f 100644 --- a/core/import/import_suite_test.go +++ b/core/import/import_test.go @@ -6,27 +6,22 @@ import ( "testing" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/spf13/afero" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/yandex/pandora/core" "github.com/yandex/pandora/core/config" "github.com/yandex/pandora/core/coretest" "github.com/yandex/pandora/core/plugin" - "github.com/yandex/pandora/lib/ginkgoutil" "github.com/yandex/pandora/lib/testutil" "go.uber.org/zap" ) -func TestImport(t *testing.T) { +func Test_PluginConfig(t *testing.T) { defer resetGlobals() Import(afero.NewOsFs()) - ginkgoutil.RunSuite(t, "Import Suite") -} -var _ = Describe("plugin decode", func() { - Context("composite schedule", func() { + t.Run("composite schedule", func(t *testing.T) { input := func() map[string]interface{} { return map[string]interface{}{ "schedule": []map[string]interface{}{ @@ -36,27 +31,27 @@ var _ = Describe("plugin decode", func() { } } - It("plugin", func() { + t.Run("plugin", func(t *testing.T) { var conf struct { Schedule core.Schedule } err := config.Decode(input(), &conf) - Expect(err).NotTo(HaveOccurred()) - coretest.ExpectScheduleNexts(conf.Schedule, 0, 0, time.Second) + assert.NoError(t, err) + coretest.ExpectScheduleNextsT(t, conf.Schedule, 0, 0, time.Second) }) - It("plugin factory", func() { + t.Run("plugin factory", func(t *testing.T) { var conf struct { Schedule func() (core.Schedule, error) } err := config.Decode(input(), &conf) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) sched, err := conf.Schedule() - Expect(err).NotTo(HaveOccurred()) - coretest.ExpectScheduleNexts(sched, 0, 0, time.Second) + assert.NoError(t, err) + coretest.ExpectScheduleNextsT(t, sched, 0, 0, time.Second) }) }) -}) +} func TestSink(t *testing.T) { defer resetGlobals() diff --git a/core/plugin/constructor_test.go b/core/plugin/constructor_test.go index f51b94401..a6c0d1270 100644 --- a/core/plugin/constructor_test.go +++ b/core/plugin/constructor_test.go @@ -9,330 +9,326 @@ import ( "errors" "fmt" "reflect" + "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" - . "github.com/onsi/gomega" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -var _ = Describe("plugin constructor", func() { - DescribeTable("expectations failed", - func(newPlugin interface{}) { - defer recoverExpectationFail() - newPluginConstructor(ptestType(), newPlugin) - }, - Entry("not func", - errors.New("that is not constructor")), - Entry("not implements", - func() struct{} { panic("") }), - Entry("too many args", - func(_, _ ptestConfig) ptestPlugin { panic("") }), - Entry("too many return valued", - func() (_ ptestPlugin, _, _ error) { panic("") }), - Entry("second return value is not error", - func() (_, _ ptestPlugin) { panic("") }), - ) - - Context("new plugin", func() { - newPlugin := func(newPlugin interface{}, maybeConf []reflect.Value) (interface{}, error) { - testee := newPluginConstructor(ptestType(), newPlugin) - return testee.NewPlugin(maybeConf) - } - - It("", func() { - plugin, err := newPlugin(ptestNew, nil) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) +func Test_PluginConstructor_ExpectationsFailed(t *testing.T) { + tests := []struct { + name string + newPlugin any + }{ + {"not func", errors.New("that is not constructor")}, + {"not implements", func() struct{} { panic("") }}, + {"too many args", func(_, _ ptestConfig) ptestPlugin { panic("") }}, + {"too many return valued", func() (_ ptestPlugin, _, _ error) { panic("") }}, + {"second return value is not error", func() (_, _ ptestPlugin) { panic("") }}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + defer recoverExpectationFail(t) + newPluginConstructor(ptestType(), tt.newPlugin) }) + } +} - It("more that plugin", func() { - plugin, err := newPlugin(ptestNewMoreThan, nil) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) - }) +func Test_PluginConstructor_NewPlugin(t *testing.T) { + newPlugin := func(newPlugin interface{}, maybeConf []reflect.Value) (interface{}, error) { + testee := newPluginConstructor(ptestType(), newPlugin) + return testee.NewPlugin(maybeConf) + } - It("config", func() { - plugin, err := newPlugin(ptestNewConf, confToMaybe(ptestDefaultConf())) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestDefaultValue) - }) + t.Run("", func(t *testing.T) { + plugin, err := newPlugin(ptestNew, nil) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("failed", func() { - plugin, err := newPlugin(ptestNewErrFailing, nil) - Expect(err).To(Equal(ptestCreateFailedErr)) - Expect(plugin).To(BeNil()) - }) + t.Run("more that plugin", func(t *testing.T) { + plugin, err := newPlugin(ptestNewMoreThan, nil) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) }) - Context("new factory", func() { - newFactoryOK := func(newPlugin interface{}, factoryType reflect.Type, getMaybeConf func() ([]reflect.Value, error)) interface{} { - testee := newPluginConstructor(ptestType(), newPlugin) - factory, err := testee.NewFactory(factoryType, getMaybeConf) - Expect(err).NotTo(HaveOccurred()) - return factory - } - - It("same type - no wrap", func() { - factory := newFactoryOK(ptestNew, ptestNewType(), nil) - expectSameFunc(factory, ptestNew) - }) + t.Run("config", func(t *testing.T) { + plugin, err := newPlugin(ptestNewConf, confToMaybe(ptestDefaultConf())) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestDefaultValue) + }) - It(" new impl", func() { - factory := newFactoryOK(ptestNewImpl, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("failed", func(t *testing.T) { + plugin, err := newPlugin(ptestNewErrFailing, nil) + assert.ErrorIs(t, err, ptestCreateFailedErr) + assert.Nil(t, plugin) + }) - It("more than", func() { - factory := newFactoryOK(ptestNewMoreThan, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) +} - It("add err", func() { - factory := newFactoryOK(ptestNew, ptestNewErrType(), nil) - f, ok := factory.(func() (ptestPlugin, error)) - Expect(ok).To(BeTrue()) - plugin, err := f() - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) - }) +func Test_PluginConstructor_NewFactory(t *testing.T) { + newFactoryOK := func(newPlugin interface{}, factoryType reflect.Type, getMaybeConf func() ([]reflect.Value, error)) interface{} { + testee := newPluginConstructor(ptestType(), newPlugin) + factory, err := testee.NewFactory(factoryType, getMaybeConf) + require.NoError(t, err) + return factory + } - It("trim nil err", func() { - factory := newFactoryOK(ptestNewErr, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("same type - no wrap", func(t *testing.T) { + factory := newFactoryOK(ptestNew, ptestNewType(), nil) + expectSameFunc(t, factory, ptestNew) + }) - It("config", func() { - factory := newFactoryOK(ptestNewConf, ptestNewType(), confToGetMaybe(ptestDefaultConf())) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestDefaultValue) - }) + t.Run(" new impl", func(t *testing.T) { + factory := newFactoryOK(ptestNewImpl, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("new factory, get config failed", func() { - factory := newFactoryOK(ptestNewConf, ptestNewErrType(), errToGetMaybe(ptestConfigurationFailedErr)) - f, ok := factory.(func() (ptestPlugin, error)) - Expect(ok).To(BeTrue()) - plugin, err := f() - Expect(err).To(Equal(ptestConfigurationFailedErr)) - Expect(plugin).To(BeNil()) - }) + t.Run("more than", func(t *testing.T) { + factory := newFactoryOK(ptestNewMoreThan, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) + + t.Run("add err", func(t *testing.T) { + factory := newFactoryOK(ptestNew, ptestNewErrType(), nil) + f, ok := factory.(func() (ptestPlugin, error)) + assert.True(t, ok) + plugin, err := f() + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) + + t.Run("trim nil err", func(t *testing.T) { + factory := newFactoryOK(ptestNewErr, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("no err, get config failed, throw panic", func() { - factory := newFactoryOK(ptestNewConf, ptestNewType(), errToGetMaybe(ptestConfigurationFailedErr)) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - func() { - defer func() { - r := recover() - Expect(r).To(Equal(ptestConfigurationFailedErr)) - }() - f() + t.Run("config", func(t *testing.T) { + factory := newFactoryOK(ptestNewConf, ptestNewType(), confToGetMaybe(ptestDefaultConf())) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestDefaultValue) + }) + + t.Run("new factory, get config failed", func(t *testing.T) { + factory := newFactoryOK(ptestNewConf, ptestNewErrType(), errToGetMaybe(ptestConfigurationFailedErr)) + f, ok := factory.(func() (ptestPlugin, error)) + assert.True(t, ok) + plugin, err := f() + assert.ErrorIs(t, err, ptestConfigurationFailedErr) + assert.Nil(t, plugin) + }) + + t.Run("no err, get config failed, throw panic", func(t *testing.T) { + factory := newFactoryOK(ptestNewConf, ptestNewType(), errToGetMaybe(ptestConfigurationFailedErr)) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + func() { + defer func() { + r := recover() + assert.Equal(t, ptestConfigurationFailedErr, r) }() - }) + f() + }() + }) - It("panic on trim non nil err", func() { - factory := newFactoryOK(ptestNewErrFailing, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - func() { - defer func() { - r := recover() - Expect(r).To(Equal(ptestCreateFailedErr)) - }() - f() + t.Run("panic on trim non nil err", func(t *testing.T) { + factory := newFactoryOK(ptestNewErrFailing, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + func() { + defer func() { + r := recover() + assert.Equal(t, ptestCreateFailedErr, r) }() + f() + }() + }) + +} + +func TestFactoryConstructorExpectationsFailed(t *testing.T) { + tests := []struct { + name string + newPlugin any + }{ + {"not func", errors.New("that is not constructor")}, + {"returned not func", func() error { panic("") }}, + {"too many args", func(_, _ ptestConfig) func() ptestPlugin { panic("") }}, + {"too many return valued", func() (func() ptestPlugin, error, error) { panic("") }}, + {"second return value is not error", func() (func() ptestPlugin, ptestPlugin) { panic("") }}, + {"factory accepts conf", func() func(config ptestConfig) ptestPlugin { panic("") }}, + {"not implements", func() func() struct{} { panic("") }}, + {"factory too many args", func() func(_, _ ptestConfig) ptestPlugin { panic("") }}, + {"factory too many return valued", func() func() (_ ptestPlugin, _, _ error) { panic("") }}, + {"factory second return value is not error", func() func() (_, _ ptestPlugin) { panic("") }}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + defer recoverExpectationFail(t) + newFactoryConstructor(ptestType(), tt.newPlugin) }) + } +} + +func TestFactoryConstructorNewPlugin(t *testing.T) { + newPlugin := func(newFactory interface{}, maybeConf []reflect.Value) (interface{}, error) { + testee := newFactoryConstructor(ptestType(), newFactory) + return testee.NewPlugin(maybeConf) + } + t.Run("", func(t *testing.T) { + plugin, err := newPlugin(ptestNewFactory, nil) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) }) -}) - -var _ = Describe("factory constructor", func() { - DescribeTable("expectations failed", - func(newPlugin interface{}) { - defer recoverExpectationFail() - newFactoryConstructor(ptestType(), newPlugin) - }, - Entry("not func", - errors.New("that is not constructor")), - Entry("returned not func", - func() error { panic("") }), - Entry("too many args", - func(_, _ ptestConfig) func() ptestPlugin { panic("") }), - Entry("too many return valued", - func() (func() ptestPlugin, error, error) { panic("") }), - Entry("second return value is not error", - func() (func() ptestPlugin, ptestPlugin) { panic("") }), - Entry("factory accepts conf", - func() func(config ptestConfig) ptestPlugin { panic("") }), - Entry("not implements", - func() func() struct{} { panic("") }), - Entry("factory too many args", - func() func(_, _ ptestConfig) ptestPlugin { panic("") }), - Entry("factory too many return valued", - func() func() (_ ptestPlugin, _, _ error) { panic("") }), - Entry("factory second return value is not error", - func() func() (_, _ ptestPlugin) { panic("") }), - ) - - Context("new plugin", func() { - newPlugin := func(newFactory interface{}, maybeConf []reflect.Value) (interface{}, error) { - testee := newFactoryConstructor(ptestType(), newFactory) - return testee.NewPlugin(maybeConf) - } - - It("", func() { - plugin, err := newPlugin(ptestNewFactory, nil) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) - }) - It("impl", func() { - plugin, err := newPlugin(ptestNewFactoryImpl, nil) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("impl", func(t *testing.T) { + plugin, err := newPlugin(ptestNewFactoryImpl, nil) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("impl more than", func() { - plugin, err := newPlugin(ptestNewFactoryMoreThan, nil) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("impl more than", func(t *testing.T) { + plugin, err := newPlugin(ptestNewFactoryMoreThan, nil) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("config", func() { - plugin, err := newPlugin(ptestNewFactoryConf, confToMaybe(ptestDefaultConf())) - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestDefaultValue) - }) + t.Run("config", func(t *testing.T) { + plugin, err := newPlugin(ptestNewFactoryConf, confToMaybe(ptestDefaultConf())) + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestDefaultValue) + }) - It("failed", func() { - plugin, err := newPlugin(ptestNewFactoryErrFailing, nil) - Expect(err).To(Equal(ptestCreateFailedErr)) - Expect(plugin).To(BeNil()) - }) + t.Run("failed", func(t *testing.T) { + plugin, err := newPlugin(ptestNewFactoryErrFailing, nil) + assert.ErrorIs(t, err, ptestCreateFailedErr) + assert.Nil(t, plugin) + }) - It("factory failed", func() { - plugin, err := newPlugin(ptestNewFactoryFactoryErrFailing, nil) - Expect(err).To(Equal(ptestCreateFailedErr)) - Expect(plugin).To(BeNil()) - }) + t.Run("factory failed", func(t *testing.T) { + plugin, err := newPlugin(ptestNewFactoryFactoryErrFailing, nil) + assert.ErrorIs(t, err, ptestCreateFailedErr) + assert.Nil(t, plugin) }) +} - Context("new factory", func() { - newFactory := func(newFactory interface{}, factoryType reflect.Type, getMaybeConf func() ([]reflect.Value, error)) (interface{}, error) { - testee := newFactoryConstructor(ptestType(), newFactory) - return testee.NewFactory(factoryType, getMaybeConf) - } - newFactoryOK := func(newF interface{}, factoryType reflect.Type, getMaybeConf func() ([]reflect.Value, error)) interface{} { - factory, err := newFactory(newF, factoryType, getMaybeConf) - Expect(err).NotTo(HaveOccurred()) - return factory - } - - It("no err, same type - no wrap", func() { - factory := newFactoryOK(ptestNewFactory, ptestNewType(), nil) - expectSameFunc(factory, ptestNew) - }) +func TestFactoryConstructorNewFactory(t *testing.T) { + newFactory := func(newFactory interface{}, factoryType reflect.Type, getMaybeConf func() ([]reflect.Value, error)) (interface{}, error) { + testee := newFactoryConstructor(ptestType(), newFactory) + return testee.NewFactory(factoryType, getMaybeConf) + } + newFactoryOK := func(newF interface{}, factoryType reflect.Type, getMaybeConf func() ([]reflect.Value, error)) interface{} { + factory, err := newFactory(newF, factoryType, getMaybeConf) + require.NoError(t, err) + return factory + } - It("has err, same type - no wrap", func() { - factory := newFactoryOK(ptestNewFactoryFactoryErr, ptestNewErrType(), nil) - expectSameFunc(factory, ptestNewErr) - }) + t.Run("no err, same type - no wrap", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactory, ptestNewType(), nil) + expectSameFunc(t, factory, ptestNew) + }) - It("from new impl", func() { - factory := newFactoryOK(ptestNewFactoryImpl, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("has err, same type - no wrap", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryFactoryErr, ptestNewErrType(), nil) + expectSameFunc(t, factory, ptestNewErr) + }) - It("from new impl", func() { - factory := newFactoryOK(ptestNewFactoryMoreThan, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("from new impl", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryImpl, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("add err", func() { - factory := newFactoryOK(ptestNewFactory, ptestNewErrType(), nil) - f, ok := factory.(func() (ptestPlugin, error)) - Expect(ok).To(BeTrue()) - plugin, err := f() - Expect(err).NotTo(HaveOccurred()) - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("from new impl", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryMoreThan, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("factory construction not failed", func() { - factory := newFactoryOK(ptestNewFactoryErr, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("add err", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactory, ptestNewErrType(), nil) + f, ok := factory.(func() (ptestPlugin, error)) + assert.True(t, ok) + plugin, err := f() + assert.NoError(t, err) + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("trim nil err", func() { - factory := newFactoryOK(ptestNewFactoryFactoryErr, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestInitValue) - }) + t.Run("factory construction not failed", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryErr, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("config", func() { - factory := newFactoryOK(ptestNewFactoryConf, ptestNewType(), confToGetMaybe(ptestDefaultConf())) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - plugin := f() - ptestExpectConfigValue(plugin, ptestDefaultValue) - }) + t.Run("trim nil err", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryFactoryErr, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestInitValue) + }) - It("get config failed", func() { - factory, err := newFactory(ptestNewFactoryConf, ptestNewErrType(), errToGetMaybe(ptestConfigurationFailedErr)) - Expect(err).To(Equal(ptestConfigurationFailedErr)) - Expect(factory).To(BeNil()) - }) + t.Run("config", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryConf, ptestNewType(), confToGetMaybe(ptestDefaultConf())) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + plugin := f() + ptestExpectConfigValue(t, plugin, ptestDefaultValue) + }) - It("factory create failed", func() { - factory, err := newFactory(ptestNewFactoryErrFailing, ptestNewErrType(), nil) - Expect(err).To(Equal(ptestCreateFailedErr)) - Expect(factory).To(BeNil()) - }) + t.Run("get config failed", func(t *testing.T) { + factory, err := newFactory(ptestNewFactoryConf, ptestNewErrType(), errToGetMaybe(ptestConfigurationFailedErr)) + assert.Error(t, err, ptestConfigurationFailedErr) + assert.Nil(t, factory) + }) - It("plugin create failed", func() { - factory := newFactoryOK(ptestNewFactoryFactoryErrFailing, ptestNewErrType(), nil) - f, ok := factory.(func() (ptestPlugin, error)) - Expect(ok).To(BeTrue()) - plugin, err := f() - Expect(err).To(Equal(ptestCreateFailedErr)) - Expect(plugin).To(BeNil()) - }) + t.Run("factory create failed", func(t *testing.T) { + factory, err := newFactory(ptestNewFactoryErrFailing, ptestNewErrType(), nil) + assert.ErrorIs(t, err, ptestCreateFailedErr) + assert.Nil(t, factory) + }) - It("panic on trim non nil err", func() { - factory := newFactoryOK(ptestNewFactoryFactoryErrFailing, ptestNewType(), nil) - f, ok := factory.(func() ptestPlugin) - Expect(ok).To(BeTrue()) - func() { - defer func() { - r := recover() - Expect(r).To(Equal(ptestCreateFailedErr)) - }() - f() - }() - }) + t.Run("plugin create failed", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryFactoryErrFailing, ptestNewErrType(), nil) + f, ok := factory.(func() (ptestPlugin, error)) + assert.True(t, ok) + plugin, err := f() + assert.ErrorIs(t, err, ptestCreateFailedErr) + assert.Nil(t, plugin) + }) + t.Run("panic on trim non nil err", func(t *testing.T) { + factory := newFactoryOK(ptestNewFactoryFactoryErrFailing, ptestNewType(), nil) + f, ok := factory.(func() ptestPlugin) + assert.True(t, ok) + func() { + defer func() { + r := recover() + assert.Equal(t, ptestCreateFailedErr, r) + }() + f() + }() }) -}) + +} func confToMaybe(conf interface{}) []reflect.Value { if conf != nil { @@ -353,8 +349,8 @@ func errToGetMaybe(err error) func() ([]reflect.Value, error) { } } -func expectSameFunc(f1, f2 interface{}) { +func expectSameFunc(t *testing.T, f1, f2 interface{}) { s1 := fmt.Sprint(f1) s2 := fmt.Sprint(f2) - Expect(s1).To(Equal(s2)) + assert.Equal(t, s1, s2) } diff --git a/core/plugin/plugin_suite_test.go b/core/plugin/plugin_suite_test.go deleted file mode 100644 index 0cb918eb6..000000000 --- a/core/plugin/plugin_suite_test.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2017 Yandex LLC. All rights reserved. -// Use of this source code is governed by a MPL 2.0 -// license that can be found in the LICENSE file. -// Author: Vladimir Skipor - -package plugin - -import ( - "testing" - - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestPlugin(t *testing.T) { - ginkgoutil.RunSuite(t, "Plugin Suite") -} diff --git a/core/plugin/plugin_test.go b/core/plugin/plugin_test.go index a3c9e37b5..8dcbf968d 100644 --- a/core/plugin/plugin_test.go +++ b/core/plugin/plugin_test.go @@ -6,43 +6,49 @@ package plugin import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "testing" + + "github.com/stretchr/testify/assert" ) -var _ = Describe("Default registry", func() { - BeforeEach(func() { - Register(ptestType(), ptestPluginName, ptestNewImpl) - }) - AfterEach(func() { - defaultRegistry = NewRegistry() - }) - It("lookup", func() { - Expect(Lookup(ptestType())).To(BeTrue()) - }) - It("lookup factory", func() { - Expect(LookupFactory(ptestNewErrType())).To(BeTrue()) - }) - It("new", func() { +func TestDefaultRegistry(t *testing.T) { + beforeEach := func() { Register(ptestType(), ptestPluginName, ptestNewImpl) } + afterEach := func() { defaultRegistry = NewRegistry() } + + t.Run("lookup", func(t *testing.T) { + defer afterEach() + beforeEach() + assert.True(t, Lookup(ptestType())) + }) + t.Run("lookup factory", func(t *testing.T) { + defer afterEach() + beforeEach() + assert.True(t, LookupFactory(ptestNewErrType())) + }) + t.Run("new", func(t *testing.T) { + defer afterEach() + beforeEach() plugin, err := New(ptestType(), ptestPluginName) - Expect(err).NotTo(HaveOccurred()) - Expect(plugin).NotTo(BeNil()) + assert.NoError(t, err) + assert.NotNil(t, plugin) }) - It("new factory", func() { + t.Run("new factory", func(t *testing.T) { + defer afterEach() + beforeEach() pluginFactory, err := NewFactory(ptestNewErrType(), ptestPluginName) - Expect(err).NotTo(HaveOccurred()) - Expect(pluginFactory).NotTo(BeNil()) + assert.NoError(t, err) + assert.NotNil(t, pluginFactory) }) -}) +} -var _ = Describe("type helpers", func() { - It("ptr type", func() { +func TestTypeHelpers(t *testing.T) { + t.Run("ptr type", func(t *testing.T) { var plugin ptestPlugin - Expect(PtrType(&plugin)).To(Equal(ptestType())) + assert.Equal(t, ptestType(), PtrType(&plugin)) }) - It("factory plugin type ok", func() { + t.Run("factory plugin type ok", func(t *testing.T) { factoryPlugin, ok := FactoryPluginType(ptestNewErrType()) - Expect(ok).To(BeTrue()) - Expect(factoryPlugin).To(Equal(ptestType())) + assert.True(t, ok) + assert.Equal(t, ptestType(), factoryPlugin) }) -}) +} diff --git a/core/plugin/ptest_test.go b/core/plugin/ptest_test.go index 69850d285..e8f94e75b 100644 --- a/core/plugin/ptest_test.go +++ b/core/plugin/ptest_test.go @@ -7,9 +7,10 @@ package plugin import ( "reflect" + "testing" - . "github.com/onsi/gomega" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" "github.com/yandex/pandora/core/config" ) @@ -93,16 +94,16 @@ func ptestFillConf(conf interface{}) error { return config.Decode(map[string]interface{}{"Value": ptestFilledValue}, conf) } -func ptestExpectConfigValue(conf interface{}, val string) { - conf.(ptestConfChecker).expectConfValue(val) +func ptestExpectConfigValue(t *testing.T, conf interface{}, val string) { + conf.(ptestConfChecker).expectConfValue(t, val) } type ptestConfChecker interface { - expectConfValue(string) + expectConfValue(t *testing.T, val string) } var _ ptestConfChecker = ptestConfig{} var _ ptestConfChecker = &ptestImpl{} -func (c ptestConfig) expectConfValue(val string) { Expect(c.Value).To(Equal(val)) } -func (p *ptestImpl) expectConfValue(val string) { Expect(p.Value).To(Equal(val)) } +func (c ptestConfig) expectConfValue(t *testing.T, val string) { assert.Equal(t, val, c.Value) } +func (p *ptestImpl) expectConfValue(t *testing.T, val string) { assert.Equal(t, val, p.Value) } diff --git a/core/plugin/registry_test.go b/core/plugin/registry_test.go index 5eb1da323..c22a467a1 100644 --- a/core/plugin/registry_test.go +++ b/core/plugin/registry_test.go @@ -8,294 +8,419 @@ package plugin import ( "io" "reflect" + "testing" "github.com/mitchellh/mapstructure" - . "github.com/onsi/ginkgo" - . "github.com/onsi/ginkgo/extensions/table" - . "github.com/onsi/gomega" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -var _ = Describe("new default config container", func() { - DescribeTable("expectation fail", - func(constructor interface{}, newDefaultConfigOptional ...interface{}) { - newDefaultConfig := getNewDefaultConfig(newDefaultConfigOptional) - defer recoverExpectationFail() - newDefaultConfigContainer(reflect.TypeOf(constructor), newDefaultConfig) - }, - Entry("invalid type", - func(int) ptestPlugin { return nil }), - Entry("invalid ptr type", - func(*int) ptestPlugin { return nil }), - Entry("to many args", - func(_, _ ptestConfig) ptestPlugin { return nil }), - Entry("default without config", - func() ptestPlugin { return nil }, func() *ptestConfig { return nil }), - Entry("invalid default config", - func(ptestConfig) ptestPlugin { return nil }, func() *ptestConfig { return nil }), - Entry("default config accepts args", - func(*ptestConfig) ptestPlugin { return nil }, func(int) *ptestConfig { return nil }), - ) +func TestNewDefaultConfigContainerExpectationFail(t *testing.T) { + tests := []struct { + name string + constructor any + newDefaultConfigOptional []any + }{ + { + name: "invalid type", + constructor: func(int) ptestPlugin { return nil }, + }, + { + name: "invalid ptr type", + constructor: func(*int) ptestPlugin { return nil }, + }, + { + name: "to many args", + constructor: func(_, _ ptestConfig) ptestPlugin { return nil }, + }, + { + name: "default without config", + constructor: func() ptestPlugin { return nil }, + newDefaultConfigOptional: []any{func() *ptestConfig { return nil }}}, + { + name: "invalid default config", + constructor: func(ptestConfig) ptestPlugin { return nil }, + newDefaultConfigOptional: []any{func() *ptestConfig { return nil }}}, + { + name: "default config accepts args", + constructor: func(*ptestConfig) ptestPlugin { return nil }, + newDefaultConfigOptional: []any{func(int) *ptestConfig { return nil }}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + newDefaultConfig := getNewDefaultConfig(tt.newDefaultConfigOptional) + defer recoverExpectationFail(t) + newDefaultConfigContainer(reflect.TypeOf(tt.constructor), newDefaultConfig) + }) + } +} - DescribeTable("expectation ok", - func(constructor interface{}, newDefaultConfigOptional ...interface{}) { - newDefaultConfig := getNewDefaultConfig(newDefaultConfigOptional) - container := newDefaultConfigContainer(reflect.TypeOf(constructor), newDefaultConfig) +func TestNewDefaultConfigContainerExpectationOk(t *testing.T) { + tests := []struct { + name string + constructor any + newDefaultConfigOptional []any + }{ + + { + name: "no default config", + constructor: ptestNewConf}, + { + name: "no default ptr config", + constructor: ptestNewPtrConf}, + { + name: "default config", + constructor: ptestNewConf, + newDefaultConfigOptional: []any{ptestDefaultConf}}, + { + name: "default ptr config", + constructor: ptestNewPtrConf, + newDefaultConfigOptional: []any{ptestNewDefaultPtrConf}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + newDefaultConfig := getNewDefaultConfig(tt.newDefaultConfigOptional) + container := newDefaultConfigContainer(reflect.TypeOf(tt.constructor), newDefaultConfig) conf, err := container.Get(ptestFillConf) - Expect(err).NotTo(HaveOccurred()) - Expect(conf).To(HaveLen(1)) - ptestExpectConfigValue(conf[0].Interface(), ptestFilledValue) - }, - Entry("no default config", - ptestNewConf), - Entry("no default ptr config", - ptestNewPtrConf), - Entry("default config", - ptestNewConf, ptestDefaultConf), - Entry("default ptr config", - ptestNewPtrConf, ptestNewDefaultPtrConf), - ) + assert.NoError(t, err) + assert.Len(t, conf, 1) + ptestExpectConfigValue(t, conf[0].Interface(), ptestFilledValue) + }) + } +} - It("fill no config failed", func() { - container := newDefaultConfigContainer(ptestNewErrType(), nil) - _, err := container.Get(ptestFillConf) - Expect(err).To(HaveOccurred()) - }) -}) +// new default config container fill no config failed +func TestNewDefault(t *testing.T) { + container := newDefaultConfigContainer(ptestNewErrType(), nil) + _, err := container.Get(ptestFillConf) + assert.Error(t, err) +} -var _ = Describe("registry", func() { - It("register name collision panics", func() { +func TestRegistry(t *testing.T) { + t.Run("register name collision panics", func(t *testing.T) { r := NewRegistry() r.ptestRegister(ptestNewImpl) - defer recoverExpectationFail() + defer recoverExpectationFail(t) r.ptestRegister(ptestNewImpl) }) - It("lookup", func() { + t.Run("lookup", func(t *testing.T) { r := NewRegistry() r.ptestRegister(ptestNewImpl) - Expect(r.Lookup(ptestType())).To(BeTrue()) - Expect(r.Lookup(reflect.TypeOf(0))).To(BeFalse()) - Expect(r.Lookup(reflect.TypeOf(&ptestImpl{}))).To(BeFalse()) - Expect(r.Lookup(reflect.TypeOf((*io.Writer)(nil)).Elem())).To(BeFalse()) + assert.True(t, r.Lookup(ptestType())) + assert.False(t, r.Lookup(reflect.TypeOf(0))) + assert.False(t, r.Lookup(reflect.TypeOf(&ptestImpl{}))) + assert.False(t, r.Lookup(reflect.TypeOf((*io.Writer)(nil)).Elem())) }) - It("lookup factory", func() { + t.Run("lookup factory", func(t *testing.T) { r := NewRegistry() r.ptestRegister(ptestNewImpl) - Expect(r.LookupFactory(ptestNewType())).To(BeTrue()) - Expect(r.LookupFactory(ptestNewErrType())).To(BeTrue()) + assert.True(t, r.LookupFactory(ptestNewType())) + assert.True(t, r.LookupFactory(ptestNewErrType())) - Expect(r.LookupFactory(reflect.TypeOf(0))).To(BeFalse()) - Expect(r.LookupFactory(reflect.TypeOf(&ptestImpl{}))).To(BeFalse()) - Expect(r.LookupFactory(reflect.TypeOf((*io.Writer)(nil)).Elem())).To(BeFalse()) + assert.False(t, r.LookupFactory(reflect.TypeOf(0))) + assert.False(t, r.LookupFactory(reflect.TypeOf(&ptestImpl{}))) + assert.False(t, r.LookupFactory(reflect.TypeOf((*io.Writer)(nil)).Elem())) }) +} -}) - -var _ = Describe("new", func() { +func TestNew(t *testing.T) { type New func(r *Registry, fillConfOptional ...func(conf interface{}) error) (interface{}, error) - var ( - r *Registry - testNew New - testNewOk = func(fillConfOptional ...func(conf interface{}) error) (pluginVal string) { - plugin, err := testNew(r, fillConfOptional...) - Expect(err).NotTo(HaveOccurred()) - return plugin.(*ptestImpl).Value - } - ) - BeforeEach(func() { r = NewRegistry() }) - runTestCases := func() { - Context("plugin constructor", func() { - It("no conf", func() { + + testNewOk := func(t *testing.T, r *Registry, testNew New, fillConfOptional ...func(conf interface{}) error) (pluginVal string) { + plugin, err := testNew(r, fillConfOptional...) + require.NoError(t, err) + return plugin.(*ptestImpl).Value + } + + tests := []struct { + name string + + assert func(t *testing.T, r *Registry, testNew New) + }{ + { + name: "plugin constructor. no conf", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewImpl) - Expect(testNewOk()).To(Equal(ptestInitValue)) - }) - It("nil error", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, ptestInitValue, got) + }, + }, + { + name: "plugin conf: nil error", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewErr) - Expect(testNewOk()).To(Equal(ptestInitValue)) - }) - It("non-nil error", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, ptestInitValue, got) + }, + }, + { + name: "plugin conf: non-nil error", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewErrFailing) _, err := testNew(r) - Expect(err).To(HaveOccurred()) - err = errors.Cause(err) - Expect(ptestCreateFailedErr).To(Equal(err)) - }) - It("no conf, fill conf error", func() { + assert.Error(t, err) + assert.ErrorIs(t, err, ptestCreateFailedErr) + }, + }, + { + name: "plugin conf: no conf, fill conf error", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewImpl) expectedErr := errors.New("fill conf err") _, err := testNew(r, func(_ interface{}) error { return expectedErr }) - Expect(expectedErr).To(Equal(err)) - }) - It("no default", func() { + assert.ErrorIs(t, err, expectedErr) + }, + }, + { + name: "plugin conf: no default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewConf) - Expect(testNewOk()).To(Equal("")) - }) - It("default", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, "", got) + }, + }, + { + name: "plugin conf: default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewConf, ptestDefaultConf) - Expect(testNewOk()).To(Equal(ptestDefaultValue)) - }) - It("fill conf default", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, ptestDefaultValue, got) + }, + }, + { + name: "plugin conf: fill conf default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewConf, ptestDefaultConf) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("fill conf no default", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "plugin conf: fill conf no default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewConf) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("fill ptr conf no default", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "plugin conf: fill ptr conf no default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewPtrConf) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("no default ptr conf not nil", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "plugin conf: no default ptr conf not nil", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewPtrConf) - Expect("").To(Equal(testNewOk())) - }) - It("nil default, conf not nil", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, "", got) + }, + }, + { + name: "plugin conf: nil default, conf not nil", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewPtrConf, func() *ptestConfig { return nil }) - Expect(testNewOk()).To(Equal("")) - }) - It("fill nil default", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, "", got) + }, + }, + { + name: "plugin conf: fill nil default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewPtrConf, func() *ptestConfig { return nil }) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("more than one fill conf panics", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "plugin conf: more than one fill conf panics", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewPtrConf) - defer recoverExpectationFail() + defer recoverExpectationFail(t) testNew(r, ptestFillConf, ptestFillConf) - }) - }) - - Context("factory constructor", func() { - It("no conf", func() { + }, + }, + { + name: "factory constructor; no conf", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactory) - Expect(testNewOk()).To(Equal(ptestInitValue)) - }) - It("nil error", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, ptestInitValue, got) + }, + }, + { + name: "factory constructor; nil error", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(func() (ptestPlugin, error) { return ptestNewImpl(), nil }) - Expect(testNewOk()).To(Equal(ptestInitValue)) - }) - It("non-nil error", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, ptestInitValue, got) + }, + }, + { + name: "factory constructor; non-nil error", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryFactoryErrFailing) _, err := testNew(r) - Expect(err).To(HaveOccurred()) - err = errors.Cause(err) - Expect(ptestCreateFailedErr).To(Equal(err)) - }) - It("no conf, fill conf error", func() { + assert.Error(t, err) + assert.ErrorIs(t, err, ptestCreateFailedErr) + }, + }, + { + name: "factory constructor; no conf, fill conf error", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactory) expectedErr := errors.New("fill conf err") _, err := testNew(r, func(_ interface{}) error { return expectedErr }) - Expect(expectedErr).To(Equal(err)) - }) - It("no default", func() { + assert.ErrorIs(t, err, expectedErr) + }, + }, + { + name: "factory constructor; no default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryConf) - Expect(testNewOk()).To(Equal("")) - }) - It("default", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, "", got) + }, + }, + { + name: "factory constructor; default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryConf, ptestDefaultConf) - Expect(testNewOk()).To(Equal(ptestDefaultValue)) - }) - It("fill conf default", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, ptestDefaultValue, got) + }, + }, + { + name: "factory constructor; fill conf default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryConf, ptestDefaultConf) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("fill conf no default", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "factory constructor; fill conf no default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryConf) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("fill ptr conf no default", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "factory constructor; fill ptr conf no default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryPtrConf) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("no default ptr conf not nil", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "factory constructor; no default ptr conf not nil", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryPtrConf) - Expect("").To(Equal(testNewOk())) - }) - It("nil default, conf not nil", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, "", got) + }, + }, + { + name: "factory constructor; nil default, conf not nil", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryPtrConf, func() *ptestConfig { return nil }) - Expect(testNewOk()).To(Equal("")) - }) - It("fill nil default", func() { + got := testNewOk(t, r, testNew) + assert.Equal(t, "", got) + }, + }, + { + name: "factory constructor; fill nil default", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryPtrConf, func() *ptestConfig { return nil }) - Expect(testNewOk(ptestFillConf)).To(Equal(ptestFilledValue)) - }) - It("more than one fill conf panics", func() { + got := testNewOk(t, r, testNew, ptestFillConf) + assert.Equal(t, ptestFilledValue, got) + }, + }, + { + name: "factory constructor; more than one fill conf panics", + assert: func(t *testing.T, r *Registry, testNew New) { r.ptestRegister(ptestNewFactoryPtrConf) - defer recoverExpectationFail() + defer recoverExpectationFail(t) testNew(r, ptestFillConf, ptestFillConf) - }) - }) + }, + }, } - Context("use New", func() { - BeforeEach(func() { testNew = (*Registry).ptestNew }) - runTestCases() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + r := NewRegistry() + testNew := (*Registry).ptestNew + tt.assert(t, r, testNew) - }) - Context("use NewFactory", func() { - BeforeEach(func() { testNew = (*Registry).ptestNewFactory }) - runTestCases() - }) - -}) + r = NewRegistry() + testNew = (*Registry).ptestNewFactory + tt.assert(t, r, testNew) + }) + } +} -var _ = Describe("decode", func() { - It("ok", func() { - r := NewRegistry() - const nameKey = "type" +func TestDecode(t *testing.T) { + r := NewRegistry() + const nameKey = "type" - var hook mapstructure.DecodeHookFunc - decode := func(input, result interface{}) error { - decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ - DecodeHook: hook, - ErrorUnused: true, - Result: result, - }) - if err != nil { - return err - } - return decoder.Decode(input) + var hook mapstructure.DecodeHookFunc + decode := func(input, result interface{}) error { + decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ + DecodeHook: hook, + ErrorUnused: true, + Result: result, + }) + if err != nil { + return err } - hook = mapstructure.ComposeDecodeHookFunc( - func(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error) { - if !r.Lookup(to) { - return data, nil - } - // NOTE: could be map[interface{}]interface{} here. - input := data.(map[string]interface{}) - // NOTE: should be case insensitive behaviour. - pluginName := input[nameKey].(string) - delete(input, nameKey) - return r.New(to, pluginName, func(conf interface{}) error { - // NOTE: should error, if conf has "type" field. - return decode(input, conf) - }) + return decoder.Decode(input) + } + hook = mapstructure.ComposeDecodeHookFunc( + func(from reflect.Type, to reflect.Type, data interface{}) (interface{}, error) { + if !r.Lookup(to) { + return data, nil + } + // NOTE: could be map[interface{}]interface{} here. + input := data.(map[string]interface{}) + // NOTE: should be case insensitive behaviour. + pluginName := input[nameKey].(string) + delete(input, nameKey) + return r.New(to, pluginName, func(conf interface{}) error { + // NOTE: should error, if conf has "type" field. + return decode(input, conf) }) + }) - r.Register(ptestType(), "my-plugin", ptestNewConf, ptestDefaultConf) - input := map[string]interface{}{ - "plugin": map[string]interface{}{ - nameKey: "my-plugin", - "value": ptestFilledValue, - }, - } - type Config struct { - Plugin ptestPlugin - } - var conf Config - err := decode(input, &conf) - Expect(err).NotTo(HaveOccurred()) - actualValue := conf.Plugin.(*ptestImpl).Value - Expect(actualValue).To(Equal(ptestFilledValue)) - }) - -}) + r.Register(ptestType(), "my-plugin", ptestNewConf, ptestDefaultConf) + input := map[string]interface{}{ + "plugin": map[string]interface{}{ + nameKey: "my-plugin", + "value": ptestFilledValue, + }, + } + type Config struct { + Plugin ptestPlugin + } + var conf Config + err := decode(input, &conf) + assert.NoError(t, err) + actualValue := conf.Plugin.(*ptestImpl).Value + assert.Equal(t, ptestFilledValue, actualValue) +} -func recoverExpectationFail() { +func recoverExpectationFail(t *testing.T) { r := recover() - Expect(r).NotTo(BeNil()) - Expect(r).To(ContainSubstring("expectation failed")) + assert.NotNil(t, r) + assert.Contains(t, r, "expectation failed") } diff --git a/core/provider/json_test.go b/core/provider/json_test.go index 1690d0086..807934df1 100644 --- a/core/provider/json_test.go +++ b/core/provider/json_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/yandex/pandora/core" "github.com/yandex/pandora/core/datasource" + "github.com/yandex/pandora/lib/testutil" ) type testJSONAmmo struct { @@ -166,3 +167,7 @@ func TestDecoderReset(t *testing.T) { assert.Equal(t, "first", val.Data) assert.Zero(t, val.ID) } + +func testDeps() core.ProviderDeps { + return core.ProviderDeps{Log: testutil.NewLogger()} +} diff --git a/core/provider/num_test.go b/core/provider/num_test.go index caf7242f6..a21e4ccf6 100644 --- a/core/provider/num_test.go +++ b/core/provider/num_test.go @@ -2,13 +2,13 @@ package provider import ( "context" + "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/stretchr/testify/assert" "github.com/yandex/pandora/core" ) -var _ = Describe("Num", func() { +func Test_Num(t *testing.T) { var ( limit int @@ -17,47 +17,52 @@ var _ = Describe("Num", func() { cancel context.CancelFunc runRes chan error ) - BeforeEach(func() { + beforeEach := func() { limit = 0 runRes = make(chan error) - }) - JustBeforeEach(func() { + } + justBeforeEach := func() { ctx, cancel = context.WithCancel(context.Background()) p = NewNumConf(NumConfig{limit}) go func() { runRes <- p.Run(ctx, core.ProviderDeps{}) }() - }) + } + + t.Run("unlimited", func(t *testing.T) { + beforeEach() + justBeforeEach() - It("unlimited", func() { for i := 0; i < 100; i++ { a, ok := p.Acquire() - Expect(ok).To(BeTrue()) - Expect(a).To(Equal(i)) + assert.True(t, ok) + assert.Equal(t, i, a) } cancel() - Expect(<-runRes).To(BeNil()) + + res := <-runRes + assert.NoError(t, res) + a, ok := p.Acquire() - Expect(ok).To(BeFalse()) - Expect(a).To(BeNil()) - }, 1) - - Context("unlimited", func() { - BeforeEach(func() { - limit = 50 - }) - It("", func() { - for i := 0; i < limit; i++ { - a, ok := p.Acquire() - Expect(ok).To(BeTrue()) - Expect(a).To(Equal(i)) - } + assert.False(t, ok) + assert.Nil(t, a) + }) + + t.Run("unlimited", func(t *testing.T) { + beforeEach() + limit = 50 + justBeforeEach() + + for i := 0; i < limit; i++ { a, ok := p.Acquire() - Expect(ok).To(BeFalse()) - Expect(a).To(BeNil()) - Expect(<-runRes).To(BeNil()) - }, 1) + assert.True(t, ok) + assert.Equal(t, i, a) + } + res := <-runRes + assert.NoError(t, res) + a, ok := p.Acquire() + assert.False(t, ok) + assert.Nil(t, a) }) - -}) +} diff --git a/core/provider/provider_suite_test.go b/core/provider/provider_suite_test.go deleted file mode 100644 index 1de38db7a..000000000 --- a/core/provider/provider_suite_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package provider - -import ( - "testing" - - "github.com/yandex/pandora/core" - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestProvider(t *testing.T) { - ginkgoutil.RunSuite(t, "AmmoQueue Suite") -} - -func testDeps() core.ProviderDeps { - return core.ProviderDeps{Log: ginkgoutil.NewLogger()} -} diff --git a/core/schedule/composite_test.go b/core/schedule/composite_test.go index b2df0f0c5..ed0737715 100644 --- a/core/schedule/composite_test.go +++ b/core/schedule/composite_test.go @@ -7,27 +7,27 @@ package schedule import ( "sync" + "testing" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/stretchr/testify/assert" "github.com/yandex/pandora/core" "github.com/yandex/pandora/core/coretest" "go.uber.org/atomic" ) -var _ = Describe("composite", func() { - It("empty", func() { +func Test_composite(t *testing.T) { + t.Run("empty", func(t *testing.T) { testee := NewComposite() - coretest.ExpectScheduleNexts(testee, 0) + coretest.ExpectScheduleNexts(t, testee, 0) }) - It("only", func() { + t.Run("only", func(t *testing.T) { testee := NewComposite(NewConst(1, time.Second)) - coretest.ExpectScheduleNexts(testee, 0, time.Second) + coretest.ExpectScheduleNexts(t, testee, 0, time.Second) }) - It("composite", func() { + t.Run("composite", func(t *testing.T) { testee := NewComposite( NewConst(1, 2*time.Second), NewOnce(2), @@ -35,7 +35,7 @@ var _ = Describe("composite", func() { NewOnce(0), NewOnce(1), ) - coretest.ExpectScheduleNexts(testee, + coretest.ExpectScheduleNexts(t, testee, 0, time.Second, @@ -48,7 +48,7 @@ var _ = Describe("composite", func() { }) // Load concurrently, and let race detector do it's work. - It("race", func() { + t.Run("race", func(t *testing.T) { var ( nexts []core.Schedule tokensGot atomic.Int64 @@ -80,10 +80,10 @@ var _ = Describe("composite", func() { }() } wg.Wait() - Expect(tokensGot.Load()).To(Equal(tokensExpected)) + assert.Equal(t, tokensExpected, tokensGot.Load()) }) - It("left with unknown", func() { + t.Run("left with unknown", func(t *testing.T) { unlimitedDuration := time.Second testee := NewComposite( NewUnlimited(unlimitedDuration), @@ -91,23 +91,23 @@ var _ = Describe("composite", func() { NewConst(1, 2*time.Second), NewOnce(1), ) - Expect(testee.Left()).To(Equal(-1)) + assert.Equal(t, -1, testee.Left()) startAt := time.Now().Add(-unlimitedDuration) testee.Start(startAt) unlimitedFinish := startAt.Add(unlimitedDuration) sched := testee.(*compositeSchedule).scheds[0] - Expect(sched.(*unlimitedSchedule).finish.Load()).To(Equal(unlimitedFinish)) + assert.Equal(t, unlimitedFinish, sched.(*unlimitedSchedule).finish.Load()) - Expect(testee.Left()).To(Equal(3)) + assert.Equal(t, 3, testee.Left()) - actualNexts := coretest.DrainScheduleDuration(testee, unlimitedFinish) + actualNexts := coretest.DrainScheduleDuration(t, testee, unlimitedFinish) expectedNests := []time.Duration{ 0, time.Second, 2 * time.Second, 2 * time.Second, // Finish. } - Expect(actualNexts).To(Equal(expectedNests)) + assert.Equal(t, expectedNests, actualNexts) }) -}) +} diff --git a/core/schedule/schedule_suite_test.go b/core/schedule/schedule_suite_test.go deleted file mode 100644 index aea7fe558..000000000 --- a/core/schedule/schedule_suite_test.go +++ /dev/null @@ -1,263 +0,0 @@ -package schedule - -import ( - "sort" - "testing" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/yandex/pandora/core" - "github.com/yandex/pandora/core/coretest" - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestSchedule(t *testing.T) { - ginkgoutil.RunSuite(t, "Schedule Suite") -} - -var _ = Describe("unlimited", func() { - It("", func() { - conf := UnlimitedConfig{50 * time.Millisecond} - testee := NewUnlimitedConf(conf) - start := time.Now() - finish := start.Add(conf.Duration) - Expect(testee.Left()).To(BeEquivalentTo(-1)) - testee.Start(start) - var i int - for prev := time.Now(); ; i++ { - left := testee.Left() - x, ok := testee.Next() - if !ok { - break - } - Expect(left).To(BeEquivalentTo(-1)) - Expect(x).To(BeTemporally(">", prev)) - Expect(x).To(BeTemporally("<", finish)) - } - Expect(testee.Left()).To(BeEquivalentTo(0)) - Expect(i).To(BeNumerically(">", 50)) - }) -}) - -var _ = Describe("once", func() { - It("started", func() { - testee := NewOnce(1) - coretest.ExpectScheduleNexts(testee, 0, 0) - }) - - It("unstarted", func() { - testee := NewOnce(1) - start := time.Now() - x1, ok := testee.Next() - threshold := time.Since(start) - - Expect(ok).To(BeTrue()) - Expect(x1).To(BeTemporally("~", start, threshold)) - - x2, ok := testee.Next() - Expect(ok).To(BeFalse()) - Expect(x2).To(Equal(x1)) - }) - -}) - -var _ = Describe("const", func() { - var ( - conf ConstConfig - testee core.Schedule - underlying *doAtSchedule - ) - - JustBeforeEach(func() { - testee = NewConstConf(conf) - underlying = testee.(*doAtSchedule) - }) - - Context("non-zero ops", func() { - BeforeEach(func() { - conf = ConstConfig{ - Ops: 1, - Duration: 2 * time.Second, - } - }) - It("", func() { - Expect(underlying.n).To(BeEquivalentTo(2)) - coretest.ExpectScheduleNexts(testee, 0, time.Second, 2*time.Second) - }) - }) - - Context("zero ops", func() { - BeforeEach(func() { - conf = ConstConfig{ - Ops: 0, - Duration: 2 * time.Second, - } - }) - It("", func() { - Expect(underlying.n).To(BeEquivalentTo(0)) - coretest.ExpectScheduleNexts(testee, 2*time.Second) - }) - }) -}) - -var _ = Describe("line", func() { - var ( - conf LineConfig - testee core.Schedule - underlying *doAtSchedule - ) - - JustBeforeEach(func() { - testee = NewLineConf(conf) - underlying = testee.(*doAtSchedule) - }) - - Context("too small ops", func() { - BeforeEach(func() { - conf = LineConfig{ - From: 0, - To: 1.999, - Duration: time.Second, - } - }) - It("", func() { - // Too small ops, so should not do anything. - Expect(underlying.n).To(BeEquivalentTo(0)) - coretest.ExpectScheduleNexts(testee, time.Second) - }) - }) - - Context("const ops", func() { - BeforeEach(func() { - conf = LineConfig{ - From: 1, - To: 1, - Duration: 2 * time.Second, - } - }) - - It("", func() { - Expect(underlying.n).To(BeEquivalentTo(2)) - coretest.ExpectScheduleNexts(testee, 0, time.Second, 2*time.Second) - }) - }) - - Context("zero start", func() { - BeforeEach(func() { - conf = LineConfig{ - From: 0, - To: 1, - Duration: 2 * time.Second, - } - }) - - It("", func() { - Expect(underlying.n).To(BeEquivalentTo(1)) - coretest.ExpectScheduleNexts(testee, 0, 2*time.Second) - }) - }) - - Context("non zero start", func() { - BeforeEach(func() { - conf = LineConfig{ - From: 2, - To: 8, - Duration: 2 * time.Second, - } - }) - - It("", func() { - Expect(underlying.n).To(BeEquivalentTo(10)) - start := time.Now() - testee.Start(start) - - var ( - i int - xs []time.Time - x time.Time - ) - for ok := true; ok; i++ { - x, ok = testee.Next() - xs = append(xs, x) - } - Expect(i).To(Equal(11)) - Expect(sort.SliceIsSorted(xs, func(i, j int) bool { - return xs[i].Before(xs[j]) - })).To(BeTrue()) - Expect(start.Add(conf.Duration)).To(Equal(xs[len(xs)-1])) - }) - }) - -}) - -var _ = Describe("step", func() { - It("", func() { - conf := StepConfig{ - From: 1, - To: 2, - Step: 1, - Duration: 2 * time.Second, - } - testee := NewStepConf(conf) - Expect(testee.Left()).To(Equal(6)) - - }) - -}) - -var _ = Describe("instance_step", func() { - It("", func() { - conf := InstanceStepConfig{ - From: 1, - To: 3, - Step: 1, - StepDuration: 2 * time.Second, - } - testee := NewInstanceStepConf(conf) - Expect(testee.Left()).To(Equal(3)) - - }) - -}) - -func BenchmarkLineSchedule(b *testing.B) { - schedule := NewLine(0, float64(b.N), 2*time.Second) - benchmarkScheduleNext(b, schedule) -} - -func BenchmarkLineScheduleParallel(b *testing.B) { - schedule := NewLine(0, float64(b.N), 2*time.Second) - benchmarkScheduleNextParallel(b, schedule) -} - -func BenchmarkUnlimitedSchedule(b *testing.B) { - schedule := NewUnlimited(time.Minute) - benchmarkScheduleNext(b, schedule) -} - -func BenchmarkUnlimitedScheduleParallel(b *testing.B) { - schedule := NewUnlimited(time.Minute) - benchmarkScheduleNextParallel(b, schedule) -} - -func benchmarkScheduleNextParallel(b *testing.B, schedule core.Schedule) { - run := func(pb *testing.PB) { - for pb.Next() { - schedule.Next() - } - } - schedule.Start(time.Now()) - b.ReportAllocs() - b.ResetTimer() - b.RunParallel(run) -} - -func benchmarkScheduleNext(b *testing.B, schedule core.Schedule) { - schedule.Start(time.Now()) - b.ReportAllocs() - b.ResetTimer() - for i := 0; i < b.N; i++ { - schedule.Next() - } -} diff --git a/core/schedule/schedule_test.go b/core/schedule/schedule_test.go new file mode 100644 index 000000000..ca2ab1fe1 --- /dev/null +++ b/core/schedule/schedule_test.go @@ -0,0 +1,239 @@ +package schedule + +import ( + "sort" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/yandex/pandora/core" + "github.com/yandex/pandora/core/coretest" +) + +func Test_unlimited(t *testing.T) { + conf := UnlimitedConfig{50 * time.Millisecond} + testee := NewUnlimitedConf(conf) + start := time.Now() + finish := start.Add(conf.Duration) + assert.Equal(t, -1, testee.Left()) + testee.Start(start) + var i int + for prev := time.Now(); ; i++ { + left := testee.Left() + x, ok := testee.Next() + if !ok { + break + } + assert.Equal(t, -1, left) + assert.True(t, x.After(prev)) + assert.True(t, x.Before(finish)) + } + assert.Equal(t, 0, testee.Left()) + assert.Greater(t, i, 50) +} + +func TestOnce(t *testing.T) { + t.Run("started", func(t *testing.T) { + testee := NewOnce(1) + coretest.ExpectScheduleNexts(t, testee, 0, 0) + }) + + t.Run("unstarted", func(t *testing.T) { + testee := NewOnce(1) + start := time.Now() + x1, ok := testee.Next() + threshold := time.Since(start) + + assert.True(t, ok) + assert.WithinDuration(t, start, x1, threshold) + + x2, ok := testee.Next() + assert.False(t, ok) + assert.Equal(t, x1, x2) + }) + +} + +func TestConst(t *testing.T) { + tests := []struct { + name string + conf ConstConfig + wantN int64 + wantAssertNext []time.Duration + }{ + { + name: "non-zero ops", + conf: ConstConfig{ + Ops: 1, + Duration: 2 * time.Second, + }, + wantN: 2, + wantAssertNext: []time.Duration{ + 0, time.Second, 2 * time.Second, + }, + }, + { + name: "zero ops", + conf: ConstConfig{ + Ops: 0, + Duration: 2 * time.Second, + }, + wantN: 0, + wantAssertNext: []time.Duration{ + 2 * time.Second, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + testee := NewConstConf(tt.conf) + underlying := testee.(*doAtSchedule) + + assert.Equal(t, tt.wantN, underlying.n) + coretest.ExpectScheduleNexts(t, testee, tt.wantAssertNext...) + }) + } +} + +func TestLine(t *testing.T) { + tests := []struct { + name string + conf LineConfig + wantN int64 + wantAssertNext []time.Duration + assert func(t *testing.T, testee core.Schedule, underlying *doAtSchedule) + }{ + { + name: "too small ops", + conf: LineConfig{ + From: 0, + To: 1.999, + Duration: time.Second, + }, + wantN: 0, + wantAssertNext: []time.Duration{time.Second}, + }, + { + name: "const ops", + conf: LineConfig{ + From: 1, + To: 1, + Duration: 2 * time.Second, + }, + wantN: 2, + wantAssertNext: []time.Duration{0, time.Second, 2 * time.Second}, + }, + { + name: "zero start", + conf: LineConfig{ + From: 0, + To: 1, + Duration: 2 * time.Second, + }, + wantN: 1, + wantAssertNext: []time.Duration{0, 2 * time.Second}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + testee := NewLineConf(tt.conf) + underlying := testee.(*doAtSchedule) + + assert.Equal(t, tt.wantN, underlying.n) + coretest.ExpectScheduleNexts(t, testee, tt.wantAssertNext...) + }) + } +} + +func TestLineNonZeroStart(t *testing.T) { + testee := NewLineConf(LineConfig{ + From: 2, + To: 8, + Duration: 2 * time.Second, + }) + underlying := testee.(*doAtSchedule) + + assert.Equal(t, int64(10), underlying.n) + + start := time.Now() + testee.Start(start) + + var ( + i int + xs []time.Time + x time.Time + ) + for ok := true; ok; i++ { + x, ok = testee.Next() + xs = append(xs, x) + } + assert.Equal(t, 11, i) + assert.True(t, sort.SliceIsSorted(xs, func(i, j int) bool { + return xs[i].Before(xs[j]) + })) + assert.Equal(t, xs[len(xs)-1], start.Add(2*time.Second)) +} + +func TestStep(t *testing.T) { + conf := StepConfig{ + From: 1, + To: 2, + Step: 1, + Duration: 2 * time.Second, + } + testee := NewStepConf(conf) + assert.Equal(t, 6, testee.Left()) +} + +func TestInstanceStep(t *testing.T) { + conf := InstanceStepConfig{ + From: 1, + To: 3, + Step: 1, + StepDuration: 2 * time.Second, + } + testee := NewInstanceStepConf(conf) + assert.Equal(t, 3, testee.Left()) +} + +func BenchmarkLineSchedule(b *testing.B) { + schedule := NewLine(0, float64(b.N), 2*time.Second) + benchmarkScheduleNext(b, schedule) +} + +func BenchmarkLineScheduleParallel(b *testing.B) { + schedule := NewLine(0, float64(b.N), 2*time.Second) + benchmarkScheduleNextParallel(b, schedule) +} + +func BenchmarkUnlimitedSchedule(b *testing.B) { + schedule := NewUnlimited(time.Minute) + benchmarkScheduleNext(b, schedule) +} + +func BenchmarkUnlimitedScheduleParallel(b *testing.B) { + schedule := NewUnlimited(time.Minute) + benchmarkScheduleNextParallel(b, schedule) +} + +func benchmarkScheduleNextParallel(b *testing.B, schedule core.Schedule) { + run := func(pb *testing.PB) { + for pb.Next() { + schedule.Next() + } + } + schedule.Start(time.Now()) + b.ReportAllocs() + b.ResetTimer() + b.RunParallel(run) +} + +func benchmarkScheduleNext(b *testing.B, schedule core.Schedule) { + schedule.Start(time.Now()) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + schedule.Next() + } +} diff --git a/go.mod b/go.mod index c961bdfc8..d3ff7c3b8 100644 --- a/go.mod +++ b/go.mod @@ -13,11 +13,9 @@ require ( github.com/golang/protobuf v1.5.3 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/hcl/v2 v2.16.2 - github.com/jhump/protoreflect v1.15.1 + github.com/jhump/protoreflect v1.15.6 github.com/json-iterator/go v1.1.12 github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 - github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.27.10 github.com/pkg/errors v0.9.1 github.com/spf13/afero v1.9.5 github.com/spf13/viper v1.16.0 @@ -27,40 +25,32 @@ require ( golang.org/x/exp v0.0.0-20230905200255-921286631fa9 golang.org/x/net v0.19.0 golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 - google.golang.org/grpc v1.58.2 - google.golang.org/protobuf v1.31.0 + google.golang.org/grpc v1.60.1 + google.golang.org/protobuf v1.32.0 gopkg.in/bluesuncorp/validator.v9 v9.10.0 gopkg.in/yaml.v2 v2.4.0 ) require ( - github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver v1.5.0 // indirect github.com/PaesslerAG/gval v1.2.1 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect - github.com/bufbuild/protocompile v0.5.1 // indirect + github.com/bufbuild/protocompile v0.8.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/frankban/quicktest v1.14.5 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-task/slim-sprig v2.20.0+incompatible // indirect github.com/go-test/deep v1.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 // indirect - github.com/google/uuid v1.4.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect - github.com/huandu/xstrings v1.4.0 // indirect - github.com/imdario/mergo v0.3.13 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect @@ -72,17 +62,13 @@ require ( github.com/stretchr/objx v0.5.1 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/zclconf/go-cty v1.13.2 // indirect - go.uber.org/goleak v1.2.1 // indirect + go.uber.org/goleak v1.3.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/sync v0.5.0 // indirect - golang.org/x/sys v0.15.0 // indirect + golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.16.1 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c37200882..76a3287ab 100644 --- a/go.sum +++ b/go.sum @@ -38,10 +38,6 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= -github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I= github.com/PaesslerAG/gval v1.2.1 h1:Ggwtej1xCyt1994VuDCSjycybIDo3duDCDghK/xc/A0= github.com/PaesslerAG/gval v1.2.1/go.mod h1:XRFLwvmkTEdYziLdaCeCa5ImcGVrfQbeNUbVR+C6xac= @@ -58,8 +54,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6 github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= -github.com/bufbuild/protocompile v0.5.1 h1:mixz5lJX4Hiz4FpqFREJHIXLfaLBntfaJv1h+/jS+Qg= -github.com/bufbuild/protocompile v0.5.1/go.mod h1:G5iLmavmF4NsYtpZFvE3B/zFch2GIY8+wjsYLR/lc40= +github.com/bufbuild/protocompile v0.8.0 h1:9Kp1q6OkS9L4nM3FYbr8vlJnEwtbpDPQlQOVXfR+78s= +github.com/bufbuild/protocompile v0.8.0/go.mod h1:+Etjg4guZoAqzVk2czwEQP12yaxLJ8DxuqCJ9qHdH94= github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b h1:6+ZFm0flnudZzdSE0JxlhR2hKnGPcNB35BjQf4RYQDY= github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -86,22 +82,15 @@ github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4 h1:fP04zlkPjAG github.com/facebookgo/stackerr v0.0.0-20150612192056-c2fcf88613f4/go.mod h1:SBHk9aNQtiw4R4bEuzHjVmZikkUKCnO1v3lPQ21HZGk= github.com/frankban/quicktest v1.14.5 h1:dfYrrRyLtiqT9GyKXgdh+k4inNeTvmGbuSgZ3lx3GhA= github.com/frankban/quicktest v1.14.5/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-task/slim-sprig v2.20.0+incompatible h1:4Xh3bDzO29j4TWNOI+24ubc0vbVFMg2PMnXKxK54/CA= -github.com/go-task/slim-sprig v2.20.0+incompatible/go.mod h1:N/mhXZITr/EQAOErEHciKvO1bFei2Lld2Ym6h96pdy0= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -163,12 +152,8 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= -github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= @@ -183,15 +168,10 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.16.2 h1:mpkHZh/Tv+xet3sy3F9Ld4FyI2tUpWe9x3XtPx9f1a0= github.com/hashicorp/hcl/v2 v2.16.2/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= -github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= -github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= -github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= -github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/jhump/protoreflect v1.15.6 h1:WMYJbw2Wo+KOWwZFvgY0jMoVHM6i4XIvRs2RcBj5VmI= +github.com/jhump/protoreflect v1.15.6/go.mod h1:jCHoyYQIJnaabEYnbGwyo9hUqfyUMTbJw/tAut5t97E= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -219,19 +199,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -291,8 +258,8 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= -go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= @@ -304,8 +271,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= -golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -343,7 +308,6 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -365,7 +329,6 @@ golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -400,7 +363,6 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -409,10 +371,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -433,15 +392,14 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -500,12 +458,9 @@ golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82u golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= -golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -592,8 +547,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= -google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU= +google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -606,8 +561,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/bluesuncorp/validator.v9 v9.10.0 h1:eyhz/IzFglUqngYr1p7WCfKVAAQh9E/IsqJcnwG/OWg= gopkg.in/bluesuncorp/validator.v9 v9.10.0/go.mod h1:sz1RrKEIYJCpC5S6ruDsBWo5vYV69E+bEZ86LbUsSZ8= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -616,20 +571,14 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/lib/errutil/errutil_suite_test.go b/lib/errutil/errutil_suite_test.go deleted file mode 100644 index 48e59214d..000000000 --- a/lib/errutil/errutil_suite_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package errutil - -import ( - "context" - "fmt" - "testing" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/pkg/errors" - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestErrutil(t *testing.T) { - ginkgoutil.RunSuite(t, "Errutil Suite") -} - -var _ = Describe("Iscoreutil.IsCtxErroror", func() { - canceledContext, cancel := context.WithCancel(context.Background()) - cancel() - - It("nil error", func() { - Expect(IsCtxError(context.Background(), nil)).To(BeTrue()) - Expect(IsCtxError(canceledContext, nil)).To(BeTrue()) - }) - - It("context error", func() { - Expect(IsCtxError(context.Background(), context.Canceled)).To(BeFalse()) - Expect(IsCtxError(canceledContext, context.Canceled)).To(BeTrue()) - }) - - It("caused by context error", func() { - Expect(IsCtxError(context.Background(), errors.Wrap(context.Canceled, "new err"))).To(BeFalse()) - Expect(IsCtxError(canceledContext, errors.Wrap(context.Canceled, "new err"))).To(BeTrue()) - }) - - It("default error wrapping has defferent result", func() { - Expect(IsCtxError(context.Background(), fmt.Errorf("new err %w", context.Canceled))).To(BeFalse()) - Expect(IsCtxError(canceledContext, fmt.Errorf("new err %w", context.Canceled))).To(BeFalse()) - }) - - It("usual error", func() { - err := errors.New("new err") - Expect(IsCtxError(canceledContext, err)).To(BeFalse()) - Expect(IsCtxError(context.Background(), err)).To(BeFalse()) - }) -}) diff --git a/lib/errutil/errutil_test.go b/lib/errutil/errutil_test.go index 9fc9cb673..4f9c49ee6 100644 --- a/lib/errutil/errutil_test.go +++ b/lib/errutil/errutil_test.go @@ -7,9 +7,41 @@ import ( "testing" pkgerrors "github.com/pkg/errors" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +func TestIscoreutilIsCtxErroror(t *testing.T) { + canceledContext, cancel := context.WithCancel(context.Background()) + cancel() + + t.Run("nil error", func(t *testing.T) { + assert.True(t, IsCtxError(context.Background(), nil)) + assert.True(t, IsCtxError(canceledContext, nil)) + }) + + t.Run("context error", func(t *testing.T) { + assert.False(t, IsCtxError(context.Background(), context.Canceled)) + assert.True(t, IsCtxError(canceledContext, context.Canceled)) + }) + + t.Run("caused by context error", func(t *testing.T) { + assert.False(t, IsCtxError(context.Background(), pkgerrors.Wrap(context.Canceled, "new err"))) + assert.True(t, IsCtxError(canceledContext, pkgerrors.Wrap(context.Canceled, "new err"))) + }) + + t.Run("default error wrapping has defferent result", func(t *testing.T) { + assert.False(t, IsCtxError(context.Background(), fmt.Errorf("new err %w", context.Canceled))) + assert.False(t, IsCtxError(canceledContext, fmt.Errorf("new err %w", context.Canceled))) + }) + + t.Run("usual error", func(t *testing.T) { + err := errors.New("new err") + assert.False(t, IsCtxError(canceledContext, err)) + assert.False(t, IsCtxError(context.Background(), err)) + }) +} + func TestJoin(t *testing.T) { type args struct { } diff --git a/lib/ginkgoutil/ginkgo.go b/lib/ginkgoutil/ginkgo.go deleted file mode 100644 index 2d1fac0c0..000000000 --- a/lib/ginkgoutil/ginkgo.go +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2017 Yandex LLC. All rights reserved. -// Use of this source code is governed by a MPL 2.0 -// license that can be found in the LICENSE file. -// Author: Vladimir Skipor - -package ginkgoutil - -import ( - "strings" - "testing" - - "github.com/onsi/ginkgo" - "github.com/onsi/gomega" - "github.com/onsi/gomega/format" - "github.com/spf13/viper" - "github.com/stretchr/testify/mock" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" -) - -func SetupSuite() { - format.UseStringerRepresentation = true // Otherwise error stacks have binary format. - ReplaceGlobalLogger() - gomega.RegisterFailHandler(ginkgo.Fail) -} - -func RunSuite(t *testing.T, description string) { - SetupSuite() - ginkgo.RunSpecs(t, description) -} - -func ReplaceGlobalLogger() *zap.Logger { - log := NewLogger() - zap.ReplaceGlobals(log) - zap.RedirectStdLog(log) - return log -} - -func NewLogger() *zap.Logger { - conf := zap.NewDevelopmentConfig() - enc := zapcore.NewConsoleEncoder(conf.EncoderConfig) - core := zapcore.NewCore(enc, zapcore.AddSync(ginkgo.GinkgoWriter), zap.DebugLevel) - log := zap.New(core, zap.AddCaller(), zap.AddStacktrace(zap.DPanicLevel)) - return log -} - -type Mock interface { - AssertExpectations(t mock.TestingT) bool - AssertNotCalled(t mock.TestingT, methodName string, arguments ...interface{}) bool -} - -func AssertExpectations(mocks ...Mock) { - for _, m := range mocks { - m.AssertExpectations(ginkgo.GinkgoT(1)) - } -} - -func AssertNotCalled(mock Mock, methodName string) { - mock.AssertNotCalled(ginkgo.GinkgoT(1), methodName) -} - -func ParseYAML(data string) map[string]interface{} { - v := viper.New() - v.SetConfigType("yaml") - err := v.ReadConfig(strings.NewReader(data)) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - return v.AllSettings() -} diff --git a/lib/ginkgoutil/matchers.go b/lib/ginkgoutil/matchers.go deleted file mode 100644 index 8049198d2..000000000 --- a/lib/ginkgoutil/matchers.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2018 Yandex LLC. All rights reserved. -// Use of this source code is governed by a MPL 2.0 -// license that can be found in the LICENSE file. -// Author: Vladimir Skipor - -package ginkgoutil - -import ( - "reflect" - - "github.com/onsi/gomega" -) - -func ExpectFuncsEqual(f1, f2 interface{}) { - val1 := reflect.ValueOf(f1) - val2 := reflect.ValueOf(f2) - gomega.Expect(val1.Pointer()).To(gomega.Equal(val2.Pointer())) -} diff --git a/lib/netutil/netutil_suite_test.go b/lib/netutil/netutil_test.go similarity index 60% rename from lib/netutil/netutil_suite_test.go rename to lib/netutil/netutil_test.go index a397d4121..92a7c9e68 100644 --- a/lib/netutil/netutil_suite_test.go +++ b/lib/netutil/netutil_test.go @@ -7,31 +7,24 @@ import ( "testing" "time" - "github.com/onsi/ginkgo" - "github.com/onsi/gomega" "github.com/pkg/errors" - "github.com/yandex/pandora/lib/ginkgoutil" + "github.com/stretchr/testify/assert" netmock "github.com/yandex/pandora/lib/netutil/mocks" ) -func TestNetutil(t *testing.T) { - ginkgoutil.RunSuite(t, "Netutil Suite") -} - -var _ = ginkgo.Describe("DNS", func() { - - ginkgo.It("lookup reachable", func() { +func Test_DNS(t *testing.T) { + t.Run("lookup reachable", func(t *testing.T) { listener, err := net.ListenTCP("tcp4", nil) defer func() { _ = listener.Close() }() - gomega.Expect(err).NotTo(gomega.HaveOccurred()) + assert.NoError(t, err) port := strconv.Itoa(listener.Addr().(*net.TCPAddr).Port) addr := "localhost:" + port expectedResolved := "127.0.0.1:" + port resolved, err := LookupReachable(addr, time.Second) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - gomega.Expect(resolved).To(gomega.Equal(expectedResolved)) + assert.NoError(t, err) + assert.Equal(t, expectedResolved, resolved) }) const ( @@ -39,19 +32,19 @@ var _ = ginkgo.Describe("DNS", func() { resolved = "[::1]:8888" ) - ginkgo.It("cache", func() { + t.Run("cache", func(t *testing.T) { cache := &SimpleDNSCache{} got, ok := cache.Get(addr) - gomega.Expect(ok).To(gomega.BeFalse()) - gomega.Expect(got).To(gomega.BeEmpty()) + assert.False(t, ok) + assert.Equal(t, "", got) cache.Add(addr, resolved) got, ok = cache.Get(addr) - gomega.Expect(ok).To(gomega.BeTrue()) - gomega.Expect(got).To(gomega.Equal(resolved)) + assert.True(t, ok) + assert.Equal(t, resolved, got) }) - ginkgo.It("Dialer cache miss", func() { + t.Run("Dialer cache miss", func(t *testing.T) { ctx := context.Background() mockConn := &netmock.Conn{} mockConn.On("RemoteAddr").Return(&net.TCPAddr{ @@ -66,13 +59,15 @@ var _ = ginkgo.Describe("DNS", func() { testee := NewDNSCachingDialer(dialer, cache) conn, err := testee.DialContext(ctx, "tcp", addr) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - gomega.Expect(conn).To(gomega.Equal(mockConn)) + assert.NoError(t, err) + assert.Equal(t, mockConn, conn) - ginkgoutil.AssertExpectations(mockConn, cache, dialer) + mockConn.AssertExpectations(t) + cache.AssertExpectations(t) + dialer.AssertExpectations(t) }) - ginkgo.It("Dialer cache hit", func() { + t.Run("Dialer cache hit", func(t *testing.T) { ctx := context.Background() mockConn := &netmock.Conn{} cache := &netmock.DNSCache{} @@ -82,13 +77,15 @@ var _ = ginkgo.Describe("DNS", func() { testee := NewDNSCachingDialer(dialer, cache) conn, err := testee.DialContext(ctx, "tcp", addr) - gomega.Expect(err).NotTo(gomega.HaveOccurred()) - gomega.Expect(conn).To(gomega.Equal(mockConn)) + assert.NoError(t, err) + assert.Equal(t, mockConn, conn) - ginkgoutil.AssertExpectations(mockConn, cache, dialer) + mockConn.AssertExpectations(t) + cache.AssertExpectations(t) + dialer.AssertExpectations(t) }) - ginkgo.It("Dialer cache miss err", func() { + t.Run("Dialer cache miss err", func(t *testing.T) { ctx := context.Background() expectedErr := errors.New("dial failed") cache := &netmock.DNSCache{} @@ -98,10 +95,11 @@ var _ = ginkgo.Describe("DNS", func() { testee := NewDNSCachingDialer(dialer, cache) conn, err := testee.DialContext(ctx, "tcp", addr) - gomega.Expect(err).To(gomega.Equal(expectedErr)) - gomega.Expect(conn).To(gomega.BeNil()) + assert.ErrorIs(t, err, expectedErr) + assert.Nil(t, conn) - ginkgoutil.AssertExpectations(cache, dialer) + cache.AssertExpectations(t) + dialer.AssertExpectations(t) }) -}) +} diff --git a/lib/testutil/util.go b/lib/testutil/util.go index d8b2be43e..1dbca87ce 100644 --- a/lib/testutil/util.go +++ b/lib/testutil/util.go @@ -7,6 +7,8 @@ package testutil import ( "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" ) func ReplaceGlobalLogger() *zap.Logger { @@ -19,9 +21,15 @@ func ReplaceGlobalLogger() *zap.Logger { func NewLogger() *zap.Logger { conf := zap.NewDevelopmentConfig() conf.OutputPaths = []string{"stdout"} + conf.Level.SetLevel(zapcore.ErrorLevel) log, err := conf.Build(zap.AddCaller(), zap.AddStacktrace(zap.PanicLevel)) if err != nil { - panic(err) + zap.L().Fatal("Logger build failed", zap.Error(err)) } return log } + +func NewNullLogger() *zap.Logger { + c, _ := observer.New(zap.InfoLevel) + return zap.New(c) +} diff --git a/lib/zaputil/stack_extract_core_test.go b/lib/zaputil/stack_extract_core_test.go index 1f09ee8a3..6aab4d9af 100644 --- a/lib/zaputil/stack_extract_core_test.go +++ b/lib/zaputil/stack_extract_core_test.go @@ -7,10 +7,10 @@ package zaputil import ( "fmt" + "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" @@ -28,20 +28,19 @@ func noStackFields2() []zapcore.Field { } } -var _ = Describe("stack_extract_core", func() { - - It("check integration", func() { +func Test_StackExtractCore(t *testing.T) { + t.Run("check integration", func(t *testing.T) { nested, logs := observer.New(zap.DebugLevel) log := zap.New(NewStackExtractCore(nested)) log.Debug("test", noStackFields1()...) - Expect(logs.Len()).To(Equal(1)) + assert.Equal(t, 1, logs.Len()) entry := logs.All()[0] - Expect(entry.Message).To(Equal("test")) - Expect(entry.Context).To(Equal(noStackFields1())) + assert.Equal(t, "test", entry.Message) + assert.Equal(t, noStackFields1(), entry.Context) }) - It("no stacks", func() { + t.Run("no stacks", func(t *testing.T) { nested, logs := observer.New(zap.DebugLevel) testee := NewStackExtractCore(nested) @@ -49,13 +48,15 @@ var _ = Describe("stack_extract_core", func() { entry := zapcore.Entry{Message: "test"} _ = testee.Write(entry, noStackFields2()) - Expect(logs.Len()).To(Equal(1)) - Expect(logs.All()[0]).To(Equal( + assert.Equal(t, 1, logs.Len()) + assert.Equal( + t, observer.LoggedEntry{Entry: entry, Context: append(noStackFields1(), noStackFields2()...)}, - )) + logs.All()[0], + ) }) - It("stack in write", func() { + t.Run("stack in write", func(t *testing.T) { const sampleErrMsg = "stacked error msg" sampleErr := errors.New(sampleErrMsg) sampleStack := fmt.Sprintf("%+v", sampleErr.(stackedErr).StackTrace()) @@ -71,17 +72,19 @@ var _ = Describe("stack_extract_core", func() { expectedEntry := entry expectedEntry.Stack = "error stacktrace:" + sampleStack - Expect(logs.Len()).To(Equal(1)) - Expect(logs.All()[0]).To(Equal( + assert.Equal(t, 1, logs.Len()) + assert.Equal( + t, observer.LoggedEntry{ Entry: expectedEntry, Context: append(noStackFields1(), zap.String("error", sampleErrMsg)), }, - )) - Expect(fields).To(Equal(fieldsCopy)) + logs.All()[0], + ) + assert.Equal(t, fieldsCopy, fields) }) - It("stack in with", func() { + t.Run("stack in with", func(t *testing.T) { const sampleErrMsg = "stacked error msg" sampleCause := fmt.Errorf(sampleErrMsg) sampleErr := errors.WithStack(sampleCause) @@ -99,17 +102,19 @@ var _ = Describe("stack_extract_core", func() { expectedEntry := entry expectedEntry.Stack = "error stacktrace:" + sampleStack - Expect(logs.Len()).To(Equal(1)) - Expect(logs.All()[0]).To(Equal( + assert.Equal(t, 1, logs.Len()) + assert.Equal( + t, observer.LoggedEntry{ Entry: expectedEntry, Context: append(noStackFields1(), zap.Error(sampleCause)), }, - )) - Expect(fields).To(Equal(fieldsCopy)) + logs.All()[0], + ) + assert.Equal(t, fieldsCopy, fields) }) - It("stacks join", func() { + t.Run("stacks join", func(t *testing.T) { const sampleErrMsg = "stacked error msg" sampleErr := errors.New(sampleErrMsg) sampleStack := fmt.Sprintf("%+v", sampleErr.(stackedErr).StackTrace()) @@ -124,13 +129,15 @@ var _ = Describe("stack_extract_core", func() { expectedEntry := entry expectedEntry.Stack = entryStack + "\n" + customKey + " stacktrace:" + sampleStack - Expect(logs.Len()).To(Equal(1)) - Expect(logs.All()[0]).To(Equal( + assert.Equal(t, 1, logs.Len()) + + assert.Equal( + t, observer.LoggedEntry{ Entry: expectedEntry, Context: []zapcore.Field{zap.String(customKey, sampleErrMsg)}, }, - )) + logs.All()[0], + ) }) - -}) +} diff --git a/lib/zaputil/zaputil_suite_test.go b/lib/zaputil/zaputil_suite_test.go deleted file mode 100644 index fbeff291d..000000000 --- a/lib/zaputil/zaputil_suite_test.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2018 Yandex LLC. All rights reserved. -// Use of this source code is governed by a MPL 2.0 -// license that can be found in the LICENSE file. -// Author: Vladimir Skipor - -package zaputil - -import ( - "testing" - - "github.com/yandex/pandora/lib/ginkgoutil" -) - -func TestZaputilSuite(t *testing.T) { - ginkgoutil.RunSuite(t, "Zaputil Suite") -}