Skip to content

Commit

Permalink
Moving auth and config packages to stretchr/testify (#1918)
Browse files Browse the repository at this point in the history
* moving auth and config packages to stretchr/testify

* review comments
  • Loading branch information
sethiay authored May 17, 2024
1 parent e12cd0e commit 2fc919d
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 138 deletions.
31 changes: 14 additions & 17 deletions internal/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@ import (
"os"
"testing"

. "github.com/jacobsa/ogletest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
storagev1 "google.golang.org/api/storage/v1"
)

const tpcUniverseDomain = "apis-tpclp.goog"

func TestAuth(t *testing.T) { RunTests(t) }

////////////////////////////////////////////////////////////////////////
// Boilerplate
////////////////////////////////////////////////////////////////////////

type AuthTest struct {
suite.Suite
}

func init() {
RegisterTestSuite(&AuthTest{})
}

func (t *AuthTest) SetUp(ti *TestInfo) {
func TestAuthSuite(t *testing.T) {
suite.Run(t, new(AuthTest))
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -47,30 +44,30 @@ func (t *AuthTest) SetUp(ti *TestInfo) {

func (t *AuthTest) TestGetUniverseDomainForGoogle() {
contents, err := os.ReadFile("testdata/google_creds.json")
AssertEq(nil, err)
assert.NoError(t.T(), err)

domain, err := getUniverseDomain(context.Background(), contents, storagev1.DevstorageFullControlScope)

ExpectEq(nil, err)
ExpectEq(universeDomainDefault, domain)
assert.NoError(t.T(), err)
assert.Equal(t.T(), universeDomainDefault, domain)
}

func (t *AuthTest) TestGetUniverseDomainForTPC() {
contents, err := os.ReadFile("testdata/tpc_creds.json")
AssertEq(nil, err)
assert.NoError(t.T(), err)

domain, err := getUniverseDomain(context.Background(), contents, storagev1.DevstorageFullControlScope)

ExpectEq(nil, err)
ExpectEq(tpcUniverseDomain, domain)
assert.NoError(t.T(), err)
assert.Equal(t.T(), tpcUniverseDomain, domain)
}

func (t *AuthTest) TestGetUniverseDomainForEmptyCreds() {
contents, err := os.ReadFile("testdata/empty_creds.json")
AssertEq(nil, err)
assert.NoError(t.T(), err)

_, err = getUniverseDomain(context.Background(), contents, storagev1.DevstorageFullControlScope)

ExpectNe(nil, err)
ExpectEq("CredentialsFromJSON(): unexpected end of JSON input", err.Error())
assert.Error(t.T(), err)
assert.Equal(t.T(), "CredentialsFromJSON(): unexpected end of JSON input", err.Error())
}
34 changes: 18 additions & 16 deletions internal/config/config_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package config
import (
"testing"

. "github.com/jacobsa/ogletest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)

func TestConfig(t *testing.T) { RunTests(t) }

////////////////////////////////////////////////////////////////////////
// Boilerplate
////////////////////////////////////////////////////////////////////////
Expand All @@ -36,9 +35,12 @@ type flags struct {
AnonymousAccess bool
}
type ConfigTest struct {
suite.Suite
}

func init() { RegisterTestSuite(&ConfigTest{}) }
func TestConfigSuite(t *testing.T) {
suite.Run(t, new(ConfigTest))
}

////////////////////////////////////////////////////////////////////////
// Tests
Expand All @@ -64,9 +66,9 @@ func (t *ConfigTest) TestOverrideLoggingFlags_WithNonEmptyLogConfigs() {

OverrideWithLoggingFlags(mountConfig, f.LogFile, f.LogFormat, f.DebugFuse, f.DebugGCS, f.DebugMutex)

AssertEq(mountConfig.LogConfig.Format, "text")
AssertEq(mountConfig.LogConfig.FilePath, "/tmp/hello.txt")
AssertEq(mountConfig.LogConfig.Severity, TRACE)
assert.Equal(t.T(), "text", mountConfig.LogConfig.Format)
assert.Equal(t.T(), "/tmp/hello.txt", mountConfig.LogConfig.FilePath)
assert.Equal(t.T(), TRACE, mountConfig.LogConfig.Severity)
}

func (t *ConfigTest) TestOverrideLoggingFlags_WithEmptyLogConfigs() {
Expand All @@ -86,9 +88,9 @@ func (t *ConfigTest) TestOverrideLoggingFlags_WithEmptyLogConfigs() {

OverrideWithLoggingFlags(mountConfig, f.LogFile, f.LogFormat, f.DebugFuse, f.DebugGCS, f.DebugMutex)

AssertEq(mountConfig.LogConfig.Format, "json")
AssertEq(mountConfig.LogConfig.FilePath, "a.txt")
AssertEq(mountConfig.LogConfig.Severity, INFO)
assert.Equal(t.T(), "json", mountConfig.LogConfig.Format)
assert.Equal(t.T(), "a.txt", mountConfig.LogConfig.FilePath)
assert.Equal(t.T(), INFO, mountConfig.LogConfig.Severity)
}

func (t *ConfigTest) TestIsFileCacheEnabled() {
Expand All @@ -98,26 +100,26 @@ func (t *ConfigTest) TestIsFileCacheEnabled() {
MaxSizeMB: -1,
},
}
AssertEq(IsFileCacheEnabled(mountConfig), true)
assert.True(t.T(), IsFileCacheEnabled(mountConfig))

mountConfig1 := &MountConfig{}
AssertEq(IsFileCacheEnabled(mountConfig1), false)
assert.False(t.T(), IsFileCacheEnabled(mountConfig1))

mountConfig2 := &MountConfig{
CacheDir: "",
FileCacheConfig: FileCacheConfig{
MaxSizeMB: -1,
},
}
AssertEq(IsFileCacheEnabled(mountConfig2), false)
assert.False(t.T(), IsFileCacheEnabled(mountConfig2))

mountConfig3 := &MountConfig{
CacheDir: "//tmp//folder//",
FileCacheConfig: FileCacheConfig{
MaxSizeMB: 0,
},
}
AssertEq(IsFileCacheEnabled(mountConfig3), false)
assert.False(t.T(), IsFileCacheEnabled(mountConfig3))
}

type TestCliContext struct {
Expand Down Expand Up @@ -151,7 +153,7 @@ func TestOverrideWithIgnoreInterruptsFlag(t *testing.T) {

OverrideWithIgnoreInterruptsFlag(testContext, mountConfig, tt.ignoreInterruptFlagValue)

AssertEq(tt.expectedIgnoreInterrupt, mountConfig.FileSystemConfig.IgnoreInterrupts)
assert.Equal(t, tt.expectedIgnoreInterrupt, mountConfig.FileSystemConfig.IgnoreInterrupts)
})
}
}
Expand Down Expand Up @@ -179,7 +181,7 @@ func TestOverrideWithAnonymousAccessFlag(t *testing.T) {

OverrideWithAnonymousAccessFlag(testContext, mountConfig, tt.anonymousAccessFlagValue)

AssertEq(tt.expectedAnonymousAccess, mountConfig.AuthConfig.AnonymousAccess)
assert.Equal(t, tt.expectedAnonymousAccess, mountConfig.AuthConfig.AnonymousAccess)
})
}
}
Loading

0 comments on commit 2fc919d

Please sign in to comment.