Add entrypoint tests
This commit is contained in:
parent
23aff4b2c8
commit
2a57fb841e
10
Godeps/Godeps.json
generated
10
Godeps/Godeps.json
generated
@ -799,6 +799,16 @@
|
||||
"ImportPath": "k8s.io/client-go/transport",
|
||||
"Comment": "v2.0.0-alpha.0",
|
||||
"Rev": "b22087a53becae45931ed72d5e0f12e0031d771a"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/onsi/gomega",
|
||||
"Comment": "v1.2.0",
|
||||
"Rev": "e85f63af4302dc0e4277c6008ecf803f1d80e4f0"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/onsi/ginkgo",
|
||||
"Comment": "v1.2.0",
|
||||
"Rev": "bb93381d543b0e5725244abe752214a110791d01"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
13
entrypoint/entrypoint_suite_test.go
Normal file
13
entrypoint/entrypoint_suite_test.go
Normal file
@ -0,0 +1,13 @@
|
||||
package entrypoint_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEntrypoint(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Entrypoint Suite")
|
||||
}
|
@ -1,9 +1,27 @@
|
||||
package entrypoint
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
cli "github.com/stackanetes/kubernetes-entrypoint/client"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/logger"
|
||||
"github.com/stackanetes/kubernetes-entrypoint/mocks"
|
||||
)
|
||||
|
||||
const (
|
||||
testNamespace = "test"
|
||||
dummyResolverName = "dummy"
|
||||
loggerInfoText = "Entrypoint INFO: "
|
||||
)
|
||||
|
||||
var testEntrypoint EntrypointInterface
|
||||
var testClient cli.ClientInterface
|
||||
|
||||
type dummyResolver struct {
|
||||
name string
|
||||
namespace string
|
||||
@ -16,10 +34,77 @@ func (d dummyResolver) GetName() (name string) {
|
||||
return d.name
|
||||
}
|
||||
|
||||
func TestRegisterNewDependency(t *testing.T) {
|
||||
dummy := dummyResolver{name: "dummy"}
|
||||
Register(dummy)
|
||||
if len(dependencies) != 1 {
|
||||
t.Errorf("Expecting dependencies len to be 1 got %v", len(dependencies))
|
||||
}
|
||||
func init() {
|
||||
testClient = mocks.NewClient()
|
||||
testEntrypoint = mocks.NewEntrypoint(testClient, testNamespace)
|
||||
|
||||
}
|
||||
|
||||
func registerNilResolver() {
|
||||
Register(nil)
|
||||
}
|
||||
|
||||
var _ = Describe("Entrypoint", func() {
|
||||
|
||||
dummy := dummyResolver{name: dummyResolverName}
|
||||
|
||||
BeforeEach(func() {
|
||||
logger.Info.SetFlags(0)
|
||||
logger.Warning.SetFlags(0)
|
||||
logger.Error.SetFlags(0)
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
// Clear dependencies
|
||||
dependencies = make([]Resolver, 0)
|
||||
})
|
||||
|
||||
It("registers new nil resolver", func() {
|
||||
defer GinkgoRecover()
|
||||
|
||||
Ω(registerNilResolver).Should(Panic())
|
||||
})
|
||||
|
||||
It("registers new non-nil resolver", func() {
|
||||
defer GinkgoRecover()
|
||||
Register(dummy)
|
||||
Expect(len(dependencies)).To(Equal(1))
|
||||
})
|
||||
|
||||
It("checks Client() method", func() {
|
||||
client := testEntrypoint.Client()
|
||||
Expect(client).To(Equal(testClient))
|
||||
})
|
||||
|
||||
It("checks Namespace() method", func() {
|
||||
ns := testEntrypoint.GetNamespace()
|
||||
Expect(ns).To(Equal(testNamespace))
|
||||
})
|
||||
|
||||
It("resolves main entrypoint with a dummy dependency", func() {
|
||||
defer GinkgoRecover()
|
||||
|
||||
// Set output logger to our reader
|
||||
r, w, _ := os.Pipe()
|
||||
tmp := os.Stdout
|
||||
defer func() {
|
||||
os.Stdout = tmp
|
||||
}()
|
||||
|
||||
logger.Info.SetOutput(w)
|
||||
|
||||
os.Stdout = w
|
||||
go func() {
|
||||
mainEntrypoint := Entrypoint{client: mocks.NewClient(), namespace: "main"}
|
||||
Register(dummy)
|
||||
mainEntrypoint.Resolve()
|
||||
w.Close()
|
||||
}()
|
||||
|
||||
// Wait for resolver to finish
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
stdout, _ := ioutil.ReadAll(r)
|
||||
Expect(string(stdout)).To(Equal(fmt.Sprintf("%sResolving %s\n%sDependency %s is resolved\n", loggerInfoText, dummyResolverName, loggerInfoText, dummyResolverName)))
|
||||
})
|
||||
})
|
||||
|
@ -2,6 +2,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v1beta1extensions "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
|
||||
api "k8s.io/client-go/pkg/api"
|
||||
unversioned "k8s.io/client-go/pkg/api/unversioned"
|
||||
|
@ -2,6 +2,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
api "k8s.io/client-go/pkg/api"
|
||||
v1 "k8s.io/client-go/pkg/api/v1"
|
||||
|
@ -1,7 +1,6 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
// "github.com/stackanetes/kubernetes-entrypoint/entrypoint"
|
||||
cli "github.com/stackanetes/kubernetes-entrypoint/client"
|
||||
)
|
||||
|
||||
@ -16,12 +15,14 @@ func (m MockEntrypoint) Resolve() {
|
||||
func (m MockEntrypoint) Client() (client cli.ClientInterface) {
|
||||
return m.client
|
||||
}
|
||||
|
||||
func (m MockEntrypoint) GetNamespace() (namespace string) {
|
||||
return m.namespace
|
||||
}
|
||||
func NewEntrypoint() MockEntrypoint {
|
||||
|
||||
func NewEntrypoint(client cli.ClientInterface, namespace string) MockEntrypoint {
|
||||
return MockEntrypoint{
|
||||
client: NewClient(),
|
||||
namespace: "test",
|
||||
client: client,
|
||||
namespace: namespace,
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v1batch "k8s.io/client-go/kubernetes/typed/batch/v1"
|
||||
api "k8s.io/client-go/pkg/api"
|
||||
v1 "k8s.io/client-go/pkg/api/v1"
|
||||
|
@ -2,6 +2,7 @@ package mocks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
api "k8s.io/client-go/pkg/api"
|
||||
v1 "k8s.io/client-go/pkg/api/v1"
|
||||
|
Loading…
Reference in New Issue
Block a user