auth

Paddy 2015-03-24 Parent:8267e1c8bcd1

153:3e8964a914ef Go to Latest

auth/postgres.go

Fix tests for scopeStore. Update all our tests to use the PG_TEST_DB environment variable if set, and use that to control whether or not the postgres tests get run. testing.Short() just wasn't working. Update ErrScopeNotFound and ErrScopeAlreadyExists to be variables instead of types, because PostgreSQL (annoyingly) offers no way to determine which specific row insertion caused the problem, and I anticipate this being a problem that is ongoing. So it's really just not worth it. Stop getScopes from returning an ErrScopeNotFound. Let's return what we find, and let the absence of what we didn't find speak for itself. Fix an error with generating the SQL for the postgres.createScopes call. We used to generate it in a way that was invalid (not joining values with ",") when more than one set of values was supplied. Hooray, testing! Update the postgres scopeStore to return ErrScopeNotFound and ErrScopeAlreadyExists errors, as appropriate. Update our tests to reflect that ErrScopeNotFound and ErrScopeAlreadyExists are now variables, not types.

History
paddy@148 1 package auth
paddy@148 2
paddy@148 3 import (
paddy@148 4 "database/sql"
paddy@149 5 )
paddy@148 6
paddy@149 7 func NewPostgres(conn string) (postgres, error) {
paddy@149 8 db, err := sql.Open("postgres", conn)
paddy@149 9 if err != nil {
paddy@149 10 return postgres{}, err
paddy@149 11 }
paddy@149 12 return postgres{db: db}, nil
paddy@149 13 }
paddy@148 14
paddy@148 15 type postgres struct {
paddy@148 16 db *sql.DB
paddy@148 17 }