Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] acceptance test package #23

Draft
wants to merge 2 commits into
base: u/robj/project-structure
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.3.0
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 // indirect
golang.org/x/text v0.3.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3 h1:ulvT7fqt0yHWzpJwI57MezWnYDVpCAYBVuYst/L+fAY=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
71 changes: 71 additions & 0 deletions pkg/acceptance/acceptance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package acceptance

import (
"bytes"
"fmt"
"log"
"os"
"os/exec"

"github.com/subosito/gotenv"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

func buildEnv(makefile string) error {
cmd := exec.Command("make", "local-env", "-f", makefile)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
log.Printf("%q", out.String())
log.Printf("%q", stderr.String())
if err != nil {
log.Fatal(err)
return err
}
env, err := gotenv.StrictParse(&out)
if err != nil {
return err
}

for key, val := range env {
fmt.Println(fmt.Sprintf("%s: %s", key, val))
if _, present := os.LookupEnv(key); !present {
os.Setenv(key, val)
}
}
return nil
}

func KubernetesCluster(makefile string) (kubernetes.ClientSet, error) {
err := buildEnv(makefile)
if err != nil {
log.Fatal(err)
return nil, err
}
cmd := exec.Command("make", "local-cluster", "-f", makefile)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err = cmd.Run()
log.Printf("%q", out.String())
log.Printf("%q", stderr.String())
if err != nil {
log.Fatal(err)
return nil, err
}

loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
if err != nil {
log.Fatal(err)
return nil, err
}
clientset, err := kubernetes.NewForConfig(config)
return clientset, nil
}
1 change: 1 addition & 0 deletions pkg/acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package acceptance
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package deployments
import (
"fmt"

paastaconfig "github.com/Yelp/paasta-tools-go/config"
paastaconfig "github.com/Yelp/paasta-tools-go/pkg/config"
)

// V2DeploymentGroup ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

paastaconfig "github.com/Yelp/paasta-tools-go/config"
paastaconfig "github.com/Yelp/paasta-tools-go/pkg/config"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion volumes/converter.go → pkg/volumes/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package volumes

import (
"fmt"
paastaconfig "github.com/Yelp/paasta-tools-go/config"
paastaconfig "github.com/Yelp/paasta-tools-go/pkg/config"
corev1 "k8s.io/api/core/v1"
"log"
"strings"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion volumes/volumes.go → pkg/volumes/volumes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package volumes

import (
"github.com/Yelp/paasta-tools-go/config"
"github.com/Yelp/paasta-tools-go/pkg/config"
)

type VolumeConfig struct {
Expand Down
File renamed without changes.