Skip to content

Commit

Permalink
Add TestMain to each test package
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Jun 17, 2024
1 parent 453e731 commit 9857eb1
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 19 deletions.
25 changes: 25 additions & 0 deletions integration/cursors/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cursors

import (
"testing"

"github.com/FerretDB/FerretDB/integration/setup"
)

func TestMain(m *testing.M) {
setup.Main(m)
}
20 changes: 1 addition & 19 deletions integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,11 @@
package integration

import (
"flag"
"os"
"testing"

"github.com/FerretDB/FerretDB/integration/setup"
)

// TestMain is the entry point for all integration tests.
func TestMain(m *testing.M) {
flag.Parse()

var code int

// ensure that Shutdown runs for any exit code or panic
func() {
// make `go test -list=.` work without side effects
if flag.Lookup("test.list").Value.String() == "" {
setup.Startup()
defer setup.Shutdown()
}

code = m.Run()
}()

os.Exit(code)
setup.Main(m)
}
25 changes: 25 additions & 0 deletions integration/oplog/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package oplog

import (
"testing"

"github.com/FerretDB/FerretDB/integration/setup"
)

func TestMain(m *testing.M) {
setup.Main(m)
}
25 changes: 25 additions & 0 deletions integration/setup/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package setup

import (
"flag"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -114,3 +117,25 @@ func Dir(tb testtb.TB) string {

return filepath.Dir(file)
}

// Main is the entry point for all integration test packages.
// It should be called from main_test.go in each package.
func Main(m *testing.M) {
flag.Parse()

var code int

// ensure that Shutdown runs for any exit code or panic
func() {
// make `go test -list=.` work without side effects
if flag.Lookup("test.list").Value.String() == "" {
Startup()

defer Shutdown()
}

code = m.Run()
}()

os.Exit(code)
}
25 changes: 25 additions & 0 deletions integration/users/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2021 FerretDB Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package users

import (
"testing"

"github.com/FerretDB/FerretDB/integration/setup"
)

func TestMain(m *testing.M) {
setup.Main(m)
}

0 comments on commit 9857eb1

Please sign in to comment.