Trivial test nits (#602)

* Ensure other repo is closed

* Prefer testlogging.Context in tests

* Prefer T.TempDir() in repotesting.Environment.Setup()
This commit is contained in:
Julio López
2020-09-10 17:26:03 -07:00
committed by GitHub
parent 70df5f738c
commit acc98d89b7
2 changed files with 8 additions and 20 deletions

View File

@@ -3,7 +3,6 @@
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -30,19 +29,9 @@ type Environment struct {
// Setup sets up a test environment.
func (e *Environment) Setup(t *testing.T, opts ...func(*repo.NewRepositoryOptions)) *Environment {
var err error
ctx := testlogging.Context(t)
e.configDir, err = ioutil.TempDir("", "")
if err != nil {
t.Fatalf("err: %v", err)
}
e.storageDir, err = ioutil.TempDir("", "")
if err != nil {
t.Fatalf("err: %v", err)
}
e.configDir = t.TempDir()
e.storageDir = t.TempDir()
opt := &repo.NewRepositoryOptions{
BlockFormat: content.FormattingOptions{
@@ -102,10 +91,6 @@ func (e *Environment) Close(ctx context.Context, t *testing.T) {
// should be empty, assuming Disconnect was successful
t.Errorf("error removing config directory: %v", err)
}
if err := os.RemoveAll(e.storageDir); err != nil {
t.Errorf("error removing storage directory: %v", err)
}
}
func (e *Environment) configFile() string {
@@ -134,6 +119,10 @@ func (e *Environment) MustOpenAnother(t *testing.T) repo.Repository {
t.Fatalf("err: %v", err)
}
t.Cleanup(func() {
rep2.Close(testlogging.Context(t))
})
return rep2
}

View File

@@ -1,7 +1,6 @@
package policy
import (
"context"
"encoding/json"
"fmt"
"sort"
@@ -15,7 +14,7 @@
)
func TestPolicyManagerInheritanceTest(t *testing.T) {
ctx := context.Background()
ctx := testlogging.Context(t)
var env repotesting.Environment
@@ -166,7 +165,7 @@ func defaultPolicyWithKeepDaily(t *testing.T, keepDaily int) *Policy {
}
func TestPolicyManagerResolvesConflicts(t *testing.T) {
ctx := context.Background()
ctx := testlogging.Context(t)
var env repotesting.Environment