Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nullbio committed May 9, 2020
1 parent 460a150 commit 7376b8c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 28 deletions.
10 changes: 0 additions & 10 deletions abcconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ func TestBindLoadEnv(t *testing.T) {
t.Error(err)
}

if cfg.DB.DB != "postgres" {
t.Errorf("expected postgres, got %s", cfg.DB.DB)
}
if cfg.DB.DBName != "lolwtf_test" {
t.Errorf("expected lolwtf_test, got %s", cfg.DB.DBName)
}
Expand Down Expand Up @@ -239,9 +236,6 @@ func TestBindPublicPathEnv(t *testing.T) {
t.Error(err)
}

if cfg.DB.DB != "postgres" {
t.Errorf("expected postgres, got %s", cfg.DB.DB)
}
if cfg.DB.DBName != "lolwtf_dev" {
t.Errorf("expected lolwtf_dev, got %s", cfg.DB.DBName)
}
Expand Down Expand Up @@ -375,9 +369,6 @@ func TestBind(t *testing.T) {
if cfg.Env != "cool" {
t.Errorf("expected env to be cool, got %s", cfg.Env)
}
if cfg.DB.DB != "postgres" {
t.Errorf("expected postgres, got %s", cfg.DB.DB)
}
if cfg.DB.Port != 5432 {
t.Errorf("expected port 5432, got %d", cfg.DB.Port)
}
Expand Down Expand Up @@ -628,7 +619,6 @@ func TestGetTagMappings(t *testing.T) {
{chain: "server.render-recompile", env: "SERVER_RENDER_RECOMPILE"},
{chain: "server.sessions-dev-storer", env: "SERVER_SESSIONS_DEV_STORER"},
{chain: "server.public-path", env: "SERVER_PUBLIC_PATH"},
{chain: "db.db", env: "DB_DB"},
{chain: "db.dbname", env: "DB_DBNAME"},
{chain: "db.host", env: "DB_HOST"},
{chain: "db.port", env: "DB_PORT"},
Expand Down
6 changes: 0 additions & 6 deletions abcdatabase/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ func TestGetConnStr(t *testing.T) {

cfg := abcconfig.DBConfig{}

_, err := GetConnStr(cfg)
if err == nil {
t.Error("expected error")
}

cfg.DB = "postgres"
cfg.User = "a"
cfg.Pass = "b"
cfg.DBName = "c"
Expand Down
4 changes: 2 additions & 2 deletions abcmiddleware/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestCustomErrorHandler(t *testing.T) {
})
w = httptest.NewRecorder()
r = httptest.NewRequest("get", "/", nil)
r = r.WithContext(context.WithValue(context.Background(), CtxLoggerKey, zap.NewNop()))
r = r.WithContext(context.WithValue(context.Background(), CTXKeyLogger, zap.NewNop()))
fn.ServeHTTP(w, r)
if rndr.status != http.StatusInternalServerError {
t.Errorf("expected StatusInternalServerError, got %d", rndr.status)
Expand All @@ -119,7 +119,7 @@ func TestCustomErrorHandler(t *testing.T) {
})
w = httptest.NewRecorder()
r = httptest.NewRequest("get", "/", nil)
r = r.WithContext(context.WithValue(context.Background(), CtxLoggerKey, zap.NewNop()))
r = r.WithContext(context.WithValue(context.Background(), CTXKeyLogger, zap.NewNop()))
fn.ServeHTTP(w, r)
if rndr.status != 100 {
t.Errorf("expected 100, got %d", rndr.status)
Expand Down
4 changes: 2 additions & 2 deletions abcmiddleware/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func TestLog(t *testing.T) {
t.Error(err)
}

ctx = context.WithValue(ctx, CtxLoggerKey, z)
ctx = context.WithValue(ctx, CTXKeyLogger, z)
r := &http.Request{}
r = r.WithContext(ctx)

// Ensure log can be called successfully. Ignore response because we don't
// need to validate anything.
_ = Log(r)
_ = Logger(r)
}
6 changes: 6 additions & 0 deletions abcmiddleware/request_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"go.uber.org/zap"
)

type bufSyncer struct {
*bytes.Buffer
}

func (bufSyncer) Sync() error { return nil }

func TestRequestID(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 3 additions & 3 deletions abcserver/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestNotFound(t *testing.T) {
notFound := n.Handler(serverCfg, render)

// set the logger on the context so calls to abcmiddleware.Log don't fail
r = r.WithContext(context.WithValue(r.Context(), abcmiddleware.CtxLoggerKey, log))
r = r.WithContext(context.WithValue(r.Context(), abcmiddleware.CTXKeyLogger, log))

// Call the handler
notFound(w, r)
Expand All @@ -140,7 +140,7 @@ func TestNotFound(t *testing.T) {
w = httptest.NewRecorder()

// set the logger on the context so calls to abcmiddleware.Log don't fail
r = r.WithContext(context.WithValue(r.Context(), abcmiddleware.CtxLoggerKey, log))
r = r.WithContext(context.WithValue(r.Context(), abcmiddleware.CTXKeyLogger, log))

// Call the handler
notFound(w, r)
Expand All @@ -157,7 +157,7 @@ func TestNotFound(t *testing.T) {
r = httptest.NewRequest("GET", "/assets/css/main-manifestmagic.css", nil)
w = httptest.NewRecorder()

r = r.WithContext(context.WithValue(r.Context(), abcmiddleware.CtxLoggerKey, log))
r = r.WithContext(context.WithValue(r.Context(), abcmiddleware.CTXKeyLogger, log))

// Set asset manifest to test manifest hotpath
manifest := map[string]string{
Expand Down
10 changes: 5 additions & 5 deletions cmd/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ func TestGetAppPath(t *testing.T) {
gopath := os.Getenv("GOPATH")
os.Setenv("GOPATH", "testpath/test")

appPath, importPath, appName, appEnvName, err := getAppPath([]string{"."})
appPath, _, importPath, appName, appEnvName, err := getAppPath([]string{".", "/templatepath"})
if err == nil {
t.Errorf("expected error, but got none: %s - %s", appPath, appName)
}

appPath, importPath, appName, appEnvName, err = getAppPath([]string{"/"})
appPath, _, importPath, appName, appEnvName, err = getAppPath([]string{"/", "/templatepath"})
if err == nil {
t.Errorf("expected error, but got none: %s - %s", appPath, appName)
}

appPath, importPath, appName, appEnvName, err = getAppPath([]string{"/test"})
appPath, _, importPath, appName, appEnvName, err = getAppPath([]string{"/test", "/templatepath"})
if err != nil {
t.Error(err)
}
Expand All @@ -45,7 +45,7 @@ func TestGetAppPath(t *testing.T) {
t.Errorf("mismatch, got %s", importPath)
}

appPath, importPath, appName, appEnvName, err = getAppPath([]string{"./stuff/test"})
appPath, _, importPath, appName, appEnvName, err = getAppPath([]string{"./stuff/test"}, "/templatepath")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestNewCmdWalk(t *testing.T) {
}

// check template file write
err = afero.WriteFile(appFS, "/templates/template.go.tmpl", []byte(`package {{.AppName}}`), 0644)
err = afero.WriteFile(appFS, "/templates/template.go.tmpl", []byte(`package {{.AppName}}`), 0644)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 7376b8c

Please sign in to comment.