storage/kubernetes: don't guess the kubeconfig location and change test env
Using the default KUBECONFIG environment variable to indicate that the Kubernetes tests should be run lead to cases where developers accidentally ran the tests. This has now been changed to "DEX_KUBECONFIG" and documentation hsa been added detailing how to run these tests. Additionally, no other storage reads environment variables for its normal configuration (outside of tests) so the Kubernetes storage no longer does. Overall, be less surprising.
This commit is contained in:
parent
ba9f6c6cd6
commit
bc16de0b58
5 changed files with 34 additions and 35 deletions
|
@ -1,12 +1,25 @@
|
||||||
# Running database tests
|
# Running integration tests
|
||||||
|
|
||||||
|
## Kubernetes
|
||||||
|
|
||||||
|
Kubernetes tests will only run if the `DEX_KUBECONFIG` environment variable is set.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ export DEX_KUBECONFIG=~/.kube/config
|
||||||
|
$ go test -v -i ./storage/kubernetes
|
||||||
|
$ go test -v ./storage/kubernetes
|
||||||
|
```
|
||||||
|
|
||||||
|
Because third party resources creation isn't synchronized it's expected that the tests fail the first time. Fear not, and just run them again.
|
||||||
|
|
||||||
|
## Postgres
|
||||||
|
|
||||||
Running database tests locally require:
|
Running database tests locally require:
|
||||||
|
|
||||||
* A systemd based Linux distro.
|
* A systemd based Linux distro.
|
||||||
* A recent version of [rkt](https://github.com/coreos/rkt) installed.
|
* A recent version of [rkt](https://github.com/coreos/rkt) installed.
|
||||||
|
|
||||||
The `standup.sh` script in the SQL directory is used to run databases in
|
The `standup.sh` script in the SQL directory is used to run databases in containers with systemd daemonizing the process.
|
||||||
containers with systemd daemonizing the process.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ sudo ./storage/sql/standup.sh create postgres
|
$ sudo ./storage/sql/standup.sh create postgres
|
||||||
|
@ -21,11 +34,10 @@ To run tests export the following environment variables:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Exporting the variables will cause the database tests to be run, rather than
|
Exporting the variables will cause the database tests to be run, rather than skipped.
|
||||||
skipped.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ # sqlite takes forever to compile, be sure to install test dependencies
|
$ # sqlite3 takes forever to compile, be sure to install test dependencies
|
||||||
$ go test -v -i ./storage/sql
|
$ go test -v -i ./storage/sql
|
||||||
$ go test -v ./storage/sql
|
$ go test -v ./storage/sql
|
||||||
```
|
```
|
6
glide.lock
generated
6
glide.lock
generated
|
@ -1,5 +1,5 @@
|
||||||
hash: 8b7a5f94584ecd144fc3ce94bb0b09f8e96c94b5a8e10d5053bd24bb597367ce
|
hash: a813cbca07393d7cbe35d411cdef588afac7a3bab8a287ffe7b9587516ef5898
|
||||||
updated: 2016-10-03T23:25:41.280181088-07:00
|
updated: 2016-10-23T20:51:55.313818678-07:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/cockroachdb/cockroach-go
|
- name: github.com/cockroachdb/cockroach-go
|
||||||
version: 31611c0501c812f437d4861d87d117053967c955
|
version: 31611c0501c812f437d4861d87d117053967c955
|
||||||
|
@ -33,8 +33,6 @@ imports:
|
||||||
- oid
|
- oid
|
||||||
- name: github.com/mattn/go-sqlite3
|
- name: github.com/mattn/go-sqlite3
|
||||||
version: 3fb7a0e792edd47bf0cf1e919dfc14e2be412e15
|
version: 3fb7a0e792edd47bf0cf1e919dfc14e2be412e15
|
||||||
- name: github.com/mitchellh/go-homedir
|
|
||||||
version: 756f7b183b7ab78acdbbee5c7f392838ed459dda
|
|
||||||
- name: github.com/pquerna/cachecontrol
|
- name: github.com/pquerna/cachecontrol
|
||||||
version: c97913dcbd76de40b051a9b4cd827f7eaeb7a868
|
version: c97913dcbd76de40b051a9b4cd827f7eaeb7a868
|
||||||
subpackages:
|
subpackages:
|
||||||
|
|
|
@ -74,9 +74,6 @@ import:
|
||||||
- proto
|
- proto
|
||||||
- protoc-gen-go
|
- protoc-gen-go
|
||||||
|
|
||||||
- package: github.com/mitchellh/go-homedir
|
|
||||||
verison: 756f7b183b7ab78acdbbee5c7f392838ed459dda
|
|
||||||
|
|
||||||
- package: github.com/kylelemons/godebug
|
- package: github.com/kylelemons/godebug
|
||||||
subpackages:
|
subpackages:
|
||||||
- diff
|
- diff
|
||||||
|
|
|
@ -5,11 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/coreos/dex/storage"
|
"github.com/coreos/dex/storage"
|
||||||
|
@ -37,8 +34,7 @@ const (
|
||||||
// Config values for the Kubernetes storage type.
|
// Config values for the Kubernetes storage type.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
InCluster bool `yaml:"inCluster"`
|
InCluster bool `yaml:"inCluster"`
|
||||||
KubeConfigPath string `yaml:"kubeConfigPath"`
|
KubeConfigFile string `yaml:"kubeConfigFile"`
|
||||||
GCFrequency int64 `yaml:"gcFrequency"` // seconds
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open returns a storage using Kubernetes third party resource.
|
// Open returns a storage using Kubernetes third party resource.
|
||||||
|
@ -52,8 +48,11 @@ func (c *Config) Open() (storage.Storage, error) {
|
||||||
|
|
||||||
// open returns a client with no garbage collection.
|
// open returns a client with no garbage collection.
|
||||||
func (c *Config) open() (*client, error) {
|
func (c *Config) open() (*client, error) {
|
||||||
if c.InCluster && (c.KubeConfigPath != "") {
|
if c.InCluster && (c.KubeConfigFile != "") {
|
||||||
return nil, errors.New("cannot specify both 'inCluster' and 'kubeConfigPath'")
|
return nil, errors.New("cannot specify both 'inCluster' and 'kubeConfigFile'")
|
||||||
|
}
|
||||||
|
if !c.InCluster && (c.KubeConfigFile == "") {
|
||||||
|
return nil, errors.New("must specify either 'inCluster' or 'kubeConfigFile'")
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -65,18 +64,7 @@ func (c *Config) open() (*client, error) {
|
||||||
if c.InCluster {
|
if c.InCluster {
|
||||||
cluster, user, namespace, err = inClusterConfig()
|
cluster, user, namespace, err = inClusterConfig()
|
||||||
} else {
|
} else {
|
||||||
kubeConfigPath := c.KubeConfigPath
|
cluster, user, namespace, err = loadKubeConfig(c.KubeConfigFile)
|
||||||
if kubeConfigPath == "" {
|
|
||||||
kubeConfigPath = os.Getenv("KUBECONFIG")
|
|
||||||
}
|
|
||||||
if kubeConfigPath == "" {
|
|
||||||
p, err := homedir.Dir()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("finding homedir: %v", err)
|
|
||||||
}
|
|
||||||
kubeConfigPath = filepath.Join(p, ".kube", "config")
|
|
||||||
}
|
|
||||||
cluster, user, namespace, err = loadKubeConfig(kubeConfigPath)
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -8,15 +8,19 @@ import (
|
||||||
"github.com/coreos/dex/storage/conformance"
|
"github.com/coreos/dex/storage/conformance"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const testKubeConfigEnv = "DEX_KUBECONFIG"
|
||||||
|
|
||||||
func TestLoadClient(t *testing.T) {
|
func TestLoadClient(t *testing.T) {
|
||||||
loadClient(t)
|
loadClient(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadClient(t *testing.T) *client {
|
func loadClient(t *testing.T) *client {
|
||||||
if os.Getenv("KUBECONFIG") == "" {
|
config := Config{
|
||||||
t.Skip()
|
KubeConfigFile: os.Getenv(testKubeConfigEnv),
|
||||||
|
}
|
||||||
|
if config.KubeConfigFile == "" {
|
||||||
|
t.Skipf("test environment variable %q not set, skipping", testKubeConfigEnv)
|
||||||
}
|
}
|
||||||
var config Config
|
|
||||||
s, err := config.open()
|
s, err := config.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Reference in a new issue