remove dot-imports for gopkg.in/check.v1

Dot-imports were only used in a couple of places, and replacing them
makes it more explicit what's imported.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-29 17:08:47 +02:00
parent 29b5e79f82
commit 3fa6d5a33b
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
5 changed files with 74 additions and 74 deletions

View file

@ -9,12 +9,12 @@ import (
"testing" "testing"
"time" "time"
. "gopkg.in/check.v1" "gopkg.in/check.v1"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
// Hook up gocheck into the "go test" runner // Hook up gocheck into the "go test" runner
func Test(t *testing.T) { TestingT(t) } func Test(t *testing.T) { check.TestingT(t) }
// configStruct is a canonical example configuration, which should map to configYamlV0_1 // configStruct is a canonical example configuration, which should map to configYamlV0_1
var configStruct = Configuration{ var configStruct = Configuration{
@ -204,51 +204,51 @@ type ConfigSuite struct {
expectedConfig *Configuration expectedConfig *Configuration
} }
var _ = Suite(new(ConfigSuite)) var _ = check.Suite(new(ConfigSuite))
func (suite *ConfigSuite) SetUpTest(c *C) { func (suite *ConfigSuite) SetUpTest(c *check.C) {
os.Clearenv() os.Clearenv()
suite.expectedConfig = copyConfig(configStruct) suite.expectedConfig = copyConfig(configStruct)
} }
// TestMarshalRoundtrip validates that configStruct can be marshaled and // TestMarshalRoundtrip validates that configStruct can be marshaled and
// unmarshaled without changing any parameters // unmarshaled without changing any parameters
func (suite *ConfigSuite) TestMarshalRoundtrip(c *C) { func (suite *ConfigSuite) TestMarshalRoundtrip(c *check.C) {
configBytes, err := yaml.Marshal(suite.expectedConfig) configBytes, err := yaml.Marshal(suite.expectedConfig)
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
config, err := Parse(bytes.NewReader(configBytes)) config, err := Parse(bytes.NewReader(configBytes))
c.Log(string(configBytes)) c.Log(string(configBytes))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseSimple validates that configYamlV0_1 can be parsed into a struct // TestParseSimple validates that configYamlV0_1 can be parsed into a struct
// matching configStruct // matching configStruct
func (suite *ConfigSuite) TestParseSimple(c *C) { func (suite *ConfigSuite) TestParseSimple(c *check.C) {
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseInmemory validates that configuration yaml with storage provided as // TestParseInmemory validates that configuration yaml with storage provided as
// a string can be parsed into a Configuration struct with no storage parameters // a string can be parsed into a Configuration struct with no storage parameters
func (suite *ConfigSuite) TestParseInmemory(c *C) { func (suite *ConfigSuite) TestParseInmemory(c *check.C) {
suite.expectedConfig.Storage = Storage{"inmemory": Parameters{}} suite.expectedConfig.Storage = Storage{"inmemory": Parameters{}}
suite.expectedConfig.Reporting = Reporting{} suite.expectedConfig.Reporting = Reporting{}
suite.expectedConfig.Log.Fields = nil suite.expectedConfig.Log.Fields = nil
config, err := Parse(bytes.NewReader([]byte(inmemoryConfigYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(inmemoryConfigYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseIncomplete validates that an incomplete yaml configuration cannot // TestParseIncomplete validates that an incomplete yaml configuration cannot
// be parsed without providing environment variables to fill in the missing // be parsed without providing environment variables to fill in the missing
// components. // components.
func (suite *ConfigSuite) TestParseIncomplete(c *C) { func (suite *ConfigSuite) TestParseIncomplete(c *check.C) {
incompleteConfigYaml := "version: 0.1" incompleteConfigYaml := "version: 0.1"
_, err := Parse(bytes.NewReader([]byte(incompleteConfigYaml))) _, err := Parse(bytes.NewReader([]byte(incompleteConfigYaml)))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
suite.expectedConfig.Log.Fields = nil suite.expectedConfig.Log.Fields = nil
suite.expectedConfig.Storage = Storage{"filesystem": Parameters{"rootdirectory": "/tmp/testroot"}} suite.expectedConfig.Storage = Storage{"filesystem": Parameters{"rootdirectory": "/tmp/testroot"}}
@ -265,28 +265,28 @@ func (suite *ConfigSuite) TestParseIncomplete(c *C) {
os.Setenv("REGISTRY_AUTH_SILLY_REALM", "silly") os.Setenv("REGISTRY_AUTH_SILLY_REALM", "silly")
config, err := Parse(bytes.NewReader([]byte(incompleteConfigYaml))) config, err := Parse(bytes.NewReader([]byte(incompleteConfigYaml)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseWithSameEnvStorage validates that providing environment variables // TestParseWithSameEnvStorage validates that providing environment variables
// that match the given storage type will only include environment-defined // that match the given storage type will only include environment-defined
// parameters and remove yaml-defined parameters // parameters and remove yaml-defined parameters
func (suite *ConfigSuite) TestParseWithSameEnvStorage(c *C) { func (suite *ConfigSuite) TestParseWithSameEnvStorage(c *check.C) {
suite.expectedConfig.Storage = Storage{"somedriver": Parameters{"region": "us-east-1"}} suite.expectedConfig.Storage = Storage{"somedriver": Parameters{"region": "us-east-1"}}
os.Setenv("REGISTRY_STORAGE", "somedriver") os.Setenv("REGISTRY_STORAGE", "somedriver")
os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_REGION", "us-east-1") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_REGION", "us-east-1")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseWithDifferentEnvStorageParams validates that providing environment variables that change // TestParseWithDifferentEnvStorageParams validates that providing environment variables that change
// and add to the given storage parameters will change and add parameters to the parsed // and add to the given storage parameters will change and add parameters to the parsed
// Configuration struct // Configuration struct
func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *C) { func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *check.C) {
suite.expectedConfig.Storage.setParameter("string1", "us-west-1") suite.expectedConfig.Storage.setParameter("string1", "us-west-1")
suite.expectedConfig.Storage.setParameter("bool1", true) suite.expectedConfig.Storage.setParameter("bool1", true)
suite.expectedConfig.Storage.setParameter("newparam", "some Value") suite.expectedConfig.Storage.setParameter("newparam", "some Value")
@ -296,26 +296,26 @@ func (suite *ConfigSuite) TestParseWithDifferentEnvStorageParams(c *C) {
os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_NEWPARAM", "some Value") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER_NEWPARAM", "some Value")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseWithDifferentEnvStorageType validates that providing an environment variable that // TestParseWithDifferentEnvStorageType validates that providing an environment variable that
// changes the storage type will be reflected in the parsed Configuration struct // changes the storage type will be reflected in the parsed Configuration struct
func (suite *ConfigSuite) TestParseWithDifferentEnvStorageType(c *C) { func (suite *ConfigSuite) TestParseWithDifferentEnvStorageType(c *check.C) {
suite.expectedConfig.Storage = Storage{"inmemory": Parameters{}} suite.expectedConfig.Storage = Storage{"inmemory": Parameters{}}
os.Setenv("REGISTRY_STORAGE", "inmemory") os.Setenv("REGISTRY_STORAGE", "inmemory")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseWithDifferentEnvStorageTypeAndParams validates that providing an environment variable // TestParseWithDifferentEnvStorageTypeAndParams validates that providing an environment variable
// that changes the storage type will be reflected in the parsed Configuration struct and that // that changes the storage type will be reflected in the parsed Configuration struct and that
// environment storage parameters will also be included // environment storage parameters will also be included
func (suite *ConfigSuite) TestParseWithDifferentEnvStorageTypeAndParams(c *C) { func (suite *ConfigSuite) TestParseWithDifferentEnvStorageTypeAndParams(c *check.C) {
suite.expectedConfig.Storage = Storage{"filesystem": Parameters{}} suite.expectedConfig.Storage = Storage{"filesystem": Parameters{}}
suite.expectedConfig.Storage.setParameter("rootdirectory", "/tmp/testroot") suite.expectedConfig.Storage.setParameter("rootdirectory", "/tmp/testroot")
@ -323,48 +323,48 @@ func (suite *ConfigSuite) TestParseWithDifferentEnvStorageTypeAndParams(c *C) {
os.Setenv("REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY", "/tmp/testroot") os.Setenv("REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY", "/tmp/testroot")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseWithSameEnvLoglevel validates that providing an environment variable defining the log // TestParseWithSameEnvLoglevel validates that providing an environment variable defining the log
// level to the same as the one provided in the yaml will not change the parsed Configuration struct // level to the same as the one provided in the yaml will not change the parsed Configuration struct
func (suite *ConfigSuite) TestParseWithSameEnvLoglevel(c *C) { func (suite *ConfigSuite) TestParseWithSameEnvLoglevel(c *check.C) {
os.Setenv("REGISTRY_LOGLEVEL", "info") os.Setenv("REGISTRY_LOGLEVEL", "info")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseWithDifferentEnvLoglevel validates that providing an environment variable defining the // TestParseWithDifferentEnvLoglevel validates that providing an environment variable defining the
// log level will override the value provided in the yaml document // log level will override the value provided in the yaml document
func (suite *ConfigSuite) TestParseWithDifferentEnvLoglevel(c *C) { func (suite *ConfigSuite) TestParseWithDifferentEnvLoglevel(c *check.C) {
suite.expectedConfig.Log.Level = "error" suite.expectedConfig.Log.Level = "error"
os.Setenv("REGISTRY_LOG_LEVEL", "error") os.Setenv("REGISTRY_LOG_LEVEL", "error")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseInvalidLoglevel validates that the parser will fail to parse a // TestParseInvalidLoglevel validates that the parser will fail to parse a
// configuration if the loglevel is malformed // configuration if the loglevel is malformed
func (suite *ConfigSuite) TestParseInvalidLoglevel(c *C) { func (suite *ConfigSuite) TestParseInvalidLoglevel(c *check.C) {
invalidConfigYaml := "version: 0.1\nloglevel: derp\nstorage: inmemory" invalidConfigYaml := "version: 0.1\nloglevel: derp\nstorage: inmemory"
_, err := Parse(bytes.NewReader([]byte(invalidConfigYaml))) _, err := Parse(bytes.NewReader([]byte(invalidConfigYaml)))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
os.Setenv("REGISTRY_LOGLEVEL", "derp") os.Setenv("REGISTRY_LOGLEVEL", "derp")
_, err = Parse(bytes.NewReader([]byte(configYamlV0_1))) _, err = Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
} }
// TestParseWithDifferentEnvReporting validates that environment variables // TestParseWithDifferentEnvReporting validates that environment variables
// properly override reporting parameters // properly override reporting parameters
func (suite *ConfigSuite) TestParseWithDifferentEnvReporting(c *C) { func (suite *ConfigSuite) TestParseWithDifferentEnvReporting(c *check.C) {
suite.expectedConfig.Reporting.Bugsnag.APIKey = "anotherBugsnagApiKey" suite.expectedConfig.Reporting.Bugsnag.APIKey = "anotherBugsnagApiKey"
suite.expectedConfig.Reporting.Bugsnag.Endpoint = "localhost:8080" suite.expectedConfig.Reporting.Bugsnag.Endpoint = "localhost:8080"
suite.expectedConfig.Reporting.NewRelic.LicenseKey = "NewRelicLicenseKey" suite.expectedConfig.Reporting.NewRelic.LicenseKey = "NewRelicLicenseKey"
@ -376,23 +376,23 @@ func (suite *ConfigSuite) TestParseWithDifferentEnvReporting(c *C) {
os.Setenv("REGISTRY_REPORTING_NEWRELIC_NAME", "some NewRelic NAME") os.Setenv("REGISTRY_REPORTING_NEWRELIC_NAME", "some NewRelic NAME")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseInvalidVersion validates that the parser will fail to parse a newer configuration // TestParseInvalidVersion validates that the parser will fail to parse a newer configuration
// version than the CurrentVersion // version than the CurrentVersion
func (suite *ConfigSuite) TestParseInvalidVersion(c *C) { func (suite *ConfigSuite) TestParseInvalidVersion(c *check.C) {
suite.expectedConfig.Version = MajorMinorVersion(CurrentVersion.Major(), CurrentVersion.Minor()+1) suite.expectedConfig.Version = MajorMinorVersion(CurrentVersion.Major(), CurrentVersion.Minor()+1)
configBytes, err := yaml.Marshal(suite.expectedConfig) configBytes, err := yaml.Marshal(suite.expectedConfig)
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
_, err = Parse(bytes.NewReader(configBytes)) _, err = Parse(bytes.NewReader(configBytes))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
} }
// TestParseExtraneousVars validates that environment variables referring to // TestParseExtraneousVars validates that environment variables referring to
// nonexistent variables don't cause side effects. // nonexistent variables don't cause side effects.
func (suite *ConfigSuite) TestParseExtraneousVars(c *C) { func (suite *ConfigSuite) TestParseExtraneousVars(c *check.C) {
suite.expectedConfig.Reporting.Bugsnag.Endpoint = "localhost:8080" suite.expectedConfig.Reporting.Bugsnag.Endpoint = "localhost:8080"
// A valid environment variable // A valid environment variable
@ -405,13 +405,13 @@ func (suite *ConfigSuite) TestParseExtraneousVars(c *C) {
os.Setenv("REGISTRY_REPORTING_ASDF", "ghjk") os.Setenv("REGISTRY_REPORTING_ASDF", "ghjk")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseEnvVarImplicitMaps validates that environment variables can set // TestParseEnvVarImplicitMaps validates that environment variables can set
// values in maps that don't already exist. // values in maps that don't already exist.
func (suite *ConfigSuite) TestParseEnvVarImplicitMaps(c *C) { func (suite *ConfigSuite) TestParseEnvVarImplicitMaps(c *check.C) {
readonly := make(map[string]interface{}) readonly := make(map[string]interface{})
readonly["enabled"] = true readonly["enabled"] = true
@ -423,41 +423,41 @@ func (suite *ConfigSuite) TestParseEnvVarImplicitMaps(c *C) {
os.Setenv("REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED", "true") os.Setenv("REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED", "true")
config, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) config, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, suite.expectedConfig) c.Assert(config, check.DeepEquals, suite.expectedConfig)
} }
// TestParseEnvWrongTypeMap validates that incorrectly attempting to unmarshal a // TestParseEnvWrongTypeMap validates that incorrectly attempting to unmarshal a
// string over existing map fails. // string over existing map fails.
func (suite *ConfigSuite) TestParseEnvWrongTypeMap(c *C) { func (suite *ConfigSuite) TestParseEnvWrongTypeMap(c *check.C) {
os.Setenv("REGISTRY_STORAGE_SOMEDRIVER", "somestring") os.Setenv("REGISTRY_STORAGE_SOMEDRIVER", "somestring")
_, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) _, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
} }
// TestParseEnvWrongTypeStruct validates that incorrectly attempting to // TestParseEnvWrongTypeStruct validates that incorrectly attempting to
// unmarshal a string into a struct fails. // unmarshal a string into a struct fails.
func (suite *ConfigSuite) TestParseEnvWrongTypeStruct(c *C) { func (suite *ConfigSuite) TestParseEnvWrongTypeStruct(c *check.C) {
os.Setenv("REGISTRY_STORAGE_LOG", "somestring") os.Setenv("REGISTRY_STORAGE_LOG", "somestring")
_, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) _, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
} }
// TestParseEnvWrongTypeSlice validates that incorrectly attempting to // TestParseEnvWrongTypeSlice validates that incorrectly attempting to
// unmarshal a string into a slice fails. // unmarshal a string into a slice fails.
func (suite *ConfigSuite) TestParseEnvWrongTypeSlice(c *C) { func (suite *ConfigSuite) TestParseEnvWrongTypeSlice(c *check.C) {
os.Setenv("REGISTRY_LOG_HOOKS", "somestring") os.Setenv("REGISTRY_LOG_HOOKS", "somestring")
_, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) _, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, NotNil) c.Assert(err, check.NotNil)
} }
// TestParseEnvMany tests several environment variable overrides. // TestParseEnvMany tests several environment variable overrides.
// The result is not checked - the goal of this test is to detect panics // The result is not checked - the goal of this test is to detect panics
// from misuse of reflection. // from misuse of reflection.
func (suite *ConfigSuite) TestParseEnvMany(c *C) { func (suite *ConfigSuite) TestParseEnvMany(c *check.C) {
os.Setenv("REGISTRY_VERSION", "0.1") os.Setenv("REGISTRY_VERSION", "0.1")
os.Setenv("REGISTRY_LOG_LEVEL", "debug") os.Setenv("REGISTRY_LOG_LEVEL", "debug")
os.Setenv("REGISTRY_LOG_FORMATTER", "json") os.Setenv("REGISTRY_LOG_FORMATTER", "json")
@ -471,10 +471,10 @@ func (suite *ConfigSuite) TestParseEnvMany(c *C) {
os.Setenv("REGISTRY_AUTH_PARAMS_VALUE2", "value2") os.Setenv("REGISTRY_AUTH_PARAMS_VALUE2", "value2")
_, err := Parse(bytes.NewReader([]byte(configYamlV0_1))) _, err := Parse(bytes.NewReader([]byte(configYamlV0_1)))
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
} }
func checkStructs(c *C, t reflect.Type, structsChecked map[string]struct{}) { func checkStructs(c *check.C, t reflect.Type, structsChecked map[string]struct{}) {
for t.Kind() == reflect.Ptr || t.Kind() == reflect.Map || t.Kind() == reflect.Slice { for t.Kind() == reflect.Ptr || t.Kind() == reflect.Map || t.Kind() == reflect.Slice {
t = t.Elem() t = t.Elem()
} }
@ -510,7 +510,7 @@ func checkStructs(c *C, t reflect.Type, structsChecked map[string]struct{}) {
// TestValidateConfigStruct makes sure that the config struct has no members // TestValidateConfigStruct makes sure that the config struct has no members
// with yaml tags that would be ambiguous to the environment variable parser. // with yaml tags that would be ambiguous to the environment variable parser.
func (suite *ConfigSuite) TestValidateConfigStruct(c *C) { func (suite *ConfigSuite) TestValidateConfigStruct(c *check.C) {
structsChecked := make(map[string]struct{}) structsChecked := make(map[string]struct{})
checkStructs(c, reflect.TypeOf(Configuration{}), structsChecked) checkStructs(c, reflect.TypeOf(Configuration{}), structsChecked)
} }

View file

@ -4,7 +4,7 @@ import (
"os" "os"
"reflect" "reflect"
. "gopkg.in/check.v1" "gopkg.in/check.v1"
) )
type localConfiguration struct { type localConfiguration struct {
@ -25,9 +25,9 @@ var expectedConfig = localConfiguration{
type ParserSuite struct{} type ParserSuite struct{}
var _ = Suite(new(ParserSuite)) var _ = check.Suite(new(ParserSuite))
func (suite *ParserSuite) TestParserOverwriteIninitializedPoiner(c *C) { func (suite *ParserSuite) TestParserOverwriteIninitializedPoiner(c *check.C) {
config := localConfiguration{} config := localConfiguration{}
os.Setenv("REGISTRY_LOG_FORMATTER", "json") os.Setenv("REGISTRY_LOG_FORMATTER", "json")
@ -44,11 +44,11 @@ func (suite *ParserSuite) TestParserOverwriteIninitializedPoiner(c *C) {
}) })
err := p.Parse([]byte(`{version: "0.1", log: {formatter: "text"}}`), &config) err := p.Parse([]byte(`{version: "0.1", log: {formatter: "text"}}`), &config)
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, expectedConfig) c.Assert(config, check.DeepEquals, expectedConfig)
} }
func (suite *ParserSuite) TestParseOverwriteUnininitializedPoiner(c *C) { func (suite *ParserSuite) TestParseOverwriteUnininitializedPoiner(c *check.C) {
config := localConfiguration{} config := localConfiguration{}
os.Setenv("REGISTRY_LOG_FORMATTER", "json") os.Setenv("REGISTRY_LOG_FORMATTER", "json")
@ -65,6 +65,6 @@ func (suite *ParserSuite) TestParseOverwriteUnininitializedPoiner(c *C) {
}) })
err := p.Parse([]byte(`{version: "0.1"}`), &config) err := p.Parse([]byte(`{version: "0.1"}`), &config)
c.Assert(err, IsNil) c.Assert(err, check.IsNil)
c.Assert(config, DeepEquals, expectedConfig) c.Assert(config, check.DeepEquals, expectedConfig)
} }

View file

@ -8,7 +8,7 @@ import (
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites" "github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
. "gopkg.in/check.v1" "gopkg.in/check.v1"
) )
const ( const (
@ -20,7 +20,7 @@ const (
) )
// Hook up gocheck into the "go test" runner. // Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) } func Test(t *testing.T) { check.TestingT(t) }
func init() { func init() {
var ( var (

View file

@ -7,11 +7,11 @@ import (
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites" "github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
. "gopkg.in/check.v1" "gopkg.in/check.v1"
) )
// Hook up gocheck into the "go test" runner. // Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) } func Test(t *testing.T) { check.TestingT(t) }
func init() { func init() {
root, err := os.MkdirTemp("", "driver-") root, err := os.MkdirTemp("", "driver-")

View file

@ -4,7 +4,7 @@ import (
"context" "context"
"testing" "testing"
check "gopkg.in/check.v1" "gopkg.in/check.v1"
) )
func Test(t *testing.T) { check.TestingT(t) } func Test(t *testing.T) { check.TestingT(t) }