Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
chore: remove unused vcr files,improve fill DB functions,rename impor…
Browse files Browse the repository at this point in the history
…ts (#715)
  • Loading branch information
MatousJobanek authored Dec 21, 2018
1 parent 5aa434f commit ed78f12
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 417 deletions.
46 changes: 23 additions & 23 deletions controller/tenants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"time"

"github.com/dgrijalva/jwt-go"
"github.com/fabric8-services/fabric8-tenant/app/test"
goatest "github.com/fabric8-services/fabric8-tenant/app/test"
"github.com/fabric8-services/fabric8-tenant/auth"
"github.com/fabric8-services/fabric8-tenant/cluster"
"github.com/fabric8-services/fabric8-tenant/configuration"
"github.com/fabric8-services/fabric8-tenant/controller"
"github.com/fabric8-services/fabric8-tenant/openshift"
"github.com/fabric8-services/fabric8-tenant/tenant"
testsupport "github.com/fabric8-services/fabric8-tenant/test"
"github.com/fabric8-services/fabric8-tenant/test"
"github.com/fabric8-services/fabric8-tenant/test/doubles"
"github.com/fabric8-services/fabric8-tenant/test/gormsupport"
"github.com/fabric8-services/fabric8-tenant/test/recorder"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (s *TenantsControllerTestSuite) TestShowTenants() {
// given
fxt := testfixture.NewTestFixture(t, s.DB, testfixture.Tenants(1), testfixture.Namespaces(1))
// when
_, tenant := test.ShowTenantsOK(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, fxt.Tenants[0].ID)
_, tenant := goatest.ShowTenantsOK(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, fxt.Tenants[0].ID)
// then
assert.Equal(t, fxt.Tenants[0].ID, *tenant.Data.ID)
assert.Equal(t, 1, len(tenant.Data.Attributes.Namespaces))
Expand All @@ -68,22 +68,22 @@ func (s *TenantsControllerTestSuite) TestShowTenants() {

t.Run("Unauhorized - no token", func(t *testing.T) {
// when/then
test.ShowTenantsUnauthorized(t, context.Background(), svc, ctrl, uuid.NewV4())
goatest.ShowTenantsUnauthorized(t, context.Background(), svc, ctrl, uuid.NewV4())
})

t.Run("Unauhorized - no SA token", func(t *testing.T) {
// when/then
test.ShowTenantsUnauthorized(t, createInvalidSAContext(), svc, ctrl, uuid.NewV4())
goatest.ShowTenantsUnauthorized(t, createInvalidSAContext(), svc, ctrl, uuid.NewV4())
})

t.Run("Unauhorized - wrong SA token", func(t *testing.T) {
// when/then
test.ShowTenantsUnauthorized(t, createValidSAContext("other service account"), svc, ctrl, uuid.NewV4())
goatest.ShowTenantsUnauthorized(t, createValidSAContext("other service account"), svc, ctrl, uuid.NewV4())
})

t.Run("Not found", func(t *testing.T) {
// when/then
test.ShowTenantsNotFound(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, uuid.NewV4())
goatest.ShowTenantsNotFound(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, uuid.NewV4())
})
})
}
Expand All @@ -100,7 +100,7 @@ func (s *TenantsControllerTestSuite) TestSearchTenants() {
// given
fxt := testfixture.NewTestFixture(t, s.DB, testfixture.Tenants(1), testfixture.Namespaces(1))
// when
_, tenant := test.SearchTenantsOK(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, fxt.Namespaces[0].MasterURL, fxt.Namespaces[0].Name)
_, tenant := goatest.SearchTenantsOK(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, fxt.Namespaces[0].MasterURL, fxt.Namespaces[0].Name)
// then
require.Len(t, tenant.Data, 1)
assert.Equal(t, fxt.Tenants[0].ID, *tenant.Data[0].ID)
Expand All @@ -110,19 +110,19 @@ func (s *TenantsControllerTestSuite) TestSearchTenants() {
s.T().Run("Failures", func(t *testing.T) {

t.Run("Unauhorized - no token", func(t *testing.T) {
test.SearchTenantsUnauthorized(t, context.Background(), svc, ctrl, "foo", "bar")
goatest.SearchTenantsUnauthorized(t, context.Background(), svc, ctrl, "foo", "bar")
})

t.Run("Unauhorized - no SA token", func(t *testing.T) {
test.SearchTenantsUnauthorized(t, createInvalidSAContext(), svc, ctrl, "foo", "bar")
goatest.SearchTenantsUnauthorized(t, createInvalidSAContext(), svc, ctrl, "foo", "bar")
})

t.Run("Unauhorized - wrong SA token", func(t *testing.T) {
test.SearchTenantsUnauthorized(t, createValidSAContext("other service account"), svc, ctrl, "foo", "bar")
goatest.SearchTenantsUnauthorized(t, createValidSAContext("other service account"), svc, ctrl, "foo", "bar")
})

t.Run("Not found", func(t *testing.T) {
test.SearchTenantsNotFound(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, "foo", "bar")
goatest.SearchTenantsNotFound(t, createValidSAContext("fabric8-jenkins-idler"), svc, ctrl, "foo", "bar")
})
})
}
Expand All @@ -134,12 +134,12 @@ func (s *TenantsControllerTestSuite) TestFailedDeleteTenants() {
testdoubles.MockCommunicationWithAuth("https://api.cluster1")
gock.New("https://api.cluster1").
Delete("/oapi/v1/projects/foo").
SetMatcher(testsupport.ExpectRequest(testsupport.HasJWTWithSub("devtools-sre"))).
SetMatcher(test.ExpectRequest(test.HasJWTWithSub("devtools-sre"))).
Reply(200).
BodyString(`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success"}`)
gock.New("https://api.cluster1").
Delete("/oapi/v1/projects/foo-che").
SetMatcher(testsupport.ExpectRequest(testsupport.HasJWTWithSub("devtools-sre"))).
SetMatcher(test.ExpectRequest(test.HasJWTWithSub("devtools-sre"))).
Reply(200).
BodyString(`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success"}`)

Expand All @@ -148,17 +148,17 @@ func (s *TenantsControllerTestSuite) TestFailedDeleteTenants() {

t.Run("Unauhorized - no token", func(t *testing.T) {
// when/then
test.DeleteTenantsUnauthorized(t, context.Background(), svc, ctrl, uuid.NewV4())
goatest.DeleteTenantsUnauthorized(t, context.Background(), svc, ctrl, uuid.NewV4())
})

t.Run("Unauhorized - no SA token", func(t *testing.T) {
// when/then
test.DeleteTenantsUnauthorized(t, createInvalidSAContext(), svc, ctrl, uuid.NewV4())
goatest.DeleteTenantsUnauthorized(t, createInvalidSAContext(), svc, ctrl, uuid.NewV4())
})

t.Run("Unauhorized - wrong SA token", func(t *testing.T) {
// when/then
test.DeleteTenantsUnauthorized(t, createValidSAContext("other service account"), svc, ctrl, uuid.NewV4())
goatest.DeleteTenantsUnauthorized(t, createValidSAContext("other service account"), svc, ctrl, uuid.NewV4())
})
})

Expand All @@ -170,12 +170,12 @@ func (s *TenantsControllerTestSuite) TestFailedDeleteTenants() {
testdoubles.MockCommunicationWithAuth("https://api.cluster1")
gock.New("https://api.cluster1").
Delete("/oapi/v1/projects/baz-che").
SetMatcher(testsupport.ExpectRequest(testsupport.HasJWTWithSub("devtools-sre"))).
SetMatcher(test.ExpectRequest(test.HasJWTWithSub("devtools-sre"))).
Reply(200).
BodyString(`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Success"}`)
gock.New("https://api.cluster1").
Delete("/oapi/v1/projects/baz").
SetMatcher(testsupport.ExpectRequest(testsupport.HasJWTWithSub("devtools-sre"))).
SetMatcher(test.ExpectRequest(test.HasJWTWithSub("devtools-sre"))).
Reply(500).
BodyString(`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Internal Server Error"}`)

Expand Down Expand Up @@ -205,7 +205,7 @@ func (s *TenantsControllerTestSuite) TestFailedDeleteTenants() {
}))

// when
test.DeleteTenantsInternalServerError(t, createValidSAContext("fabric8-auth"), svc, ctrl, fxt.Tenants[0].ID)
goatest.DeleteTenantsInternalServerError(t, createValidSAContext("fabric8-auth"), svc, ctrl, fxt.Tenants[0].ID)
// then
_, err := repo.GetTenant(fxt.Tenants[0].ID)
require.NoError(t, err)
Expand Down Expand Up @@ -241,18 +241,18 @@ func createInvalidSAContext() context.Context {
}

func prepareConfigClusterAndAuthService(t *testing.T) (cluster.Service, auth.Service, *configuration.Data, func()) {
saToken, err := testsupport.NewToken(
saToken, err := test.NewToken(
map[string]interface{}{
"sub": "tenant_service",
},
"../test/private_key.pem",
)
require.NoError(t, err)

resetVars := testsupport.SetEnvironments(testsupport.Env("F8_AUTH_TOKEN_KEY", "foo"), testsupport.Env("F8_API_SERVER_USE_TLS", "false"))
resetVars := test.SetEnvironments(test.Env("F8_AUTH_TOKEN_KEY", "foo"), test.Env("F8_API_SERVER_USE_TLS", "false"))
authService, _, cleanup :=
testdoubles.NewAuthServiceWithRecorder(t, "", "http://authservice", saToken.Raw, recorder.WithJWTMatcher)
config, resetConf := testsupport.LoadTestConfig(t)
config, resetConf := test.LoadTestConfig(t)
reset := func() {
resetVars()
cleanup()
Expand Down
10 changes: 5 additions & 5 deletions controller/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (s *UpdateControllerTestSuite) TestStartUpdateOk() {
testdoubles.SetTemplateVersions()

s.T().Run("without parameter", func(t *testing.T) {
fxt1 := tf.FillDB(t, s.DB, 6, false, tf.With().State(tenant.Ready).MasterURL("http://api.cluster1"), environment.DefaultEnvTypes...)
fxt2 := tf.FillDB(t, s.DB, 6, false, tf.With().State(tenant.Ready).MasterURL("http://api.cluster2"), environment.DefaultEnvTypes...)
fxt1 := tf.FillDB(t, s.DB, tf.AddTenants(6), false, tf.AddDefaultNamespaces().State(tenant.Ready).MasterURL("http://api.cluster1"))
fxt2 := tf.FillDB(t, s.DB, tf.AddTenants(6), false, tf.AddDefaultNamespaces().State(tenant.Ready).MasterURL("http://api.cluster2"))
configuration.Commit = "124abcd"
before := time.Now()

Expand Down Expand Up @@ -135,8 +135,8 @@ func (s *UpdateControllerTestSuite) TestStartUpdateOk() {

s.T().Run("with parameters", func(t *testing.T) {
updateExecutor.NumberOfCalls = ptr.Uint64(0)
fxt1 := tf.FillDB(t, s.DB, 6, false, tf.With().State(tenant.Ready).MasterURL("http://api.cluster1"), environment.DefaultEnvTypes...)
fxt2 := tf.FillDB(t, s.DB, 6, false, tf.With().State(tenant.Ready).MasterURL("http://api.cluster2"), environment.DefaultEnvTypes...)
fxt1 := tf.FillDB(t, s.DB, tf.AddTenants(6), false, tf.AddDefaultNamespaces().State(tenant.Ready).MasterURL("http://api.cluster1"))
fxt2 := tf.FillDB(t, s.DB, tf.AddTenants(6), false, tf.AddDefaultNamespaces().State(tenant.Ready).MasterURL("http://api.cluster2"))
configuration.Commit = "xyz"
before := time.Now()

Expand Down Expand Up @@ -294,7 +294,7 @@ func (s *UpdateControllerTestSuite) TestStopUpdateOk() {
defer reset()
testdoubles.SetTemplateVersions()

tf.FillDB(s.T(), s.DB, 50, false, tf.With().State(tenant.Ready), environment.DefaultEnvTypes...)
tf.FillDB(s.T(), s.DB, tf.AddTenants(50), false, tf.AddDefaultNamespaces().State(tenant.Ready))
configuration.Commit = "124abcd"

testupdate.Tx(s.T(), s.DB, func(repo update.Repository) error {
Expand Down
22 changes: 11 additions & 11 deletions tenant/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (s *TenantServiceTestSuite) TestGetAllTenantsToUpdate() {
// given
configuration.Commit = "123abc"
testdoubles.SetTemplateVersions()
tf.FillDB(t, s.DB, 3, false, tf.With().State(tenant.Ready), environment.DefaultEnvTypes...)
tf.FillDB(t, s.DB, tf.AddTenants(3), false, tf.AddDefaultNamespaces().State(tenant.Ready))
svc := tenant.NewDBService(s.DB)

// when
Expand All @@ -164,7 +164,7 @@ func (s *TenantServiceTestSuite) TestGetAllTenantsToUpdate() {
// given
configuration.Commit = "123abc"
testdoubles.SetTemplateVersions()
tf.FillDB(t, s.DB, 10, false, tf.With().State(tenant.Ready), environment.DefaultEnvTypes...)
tf.FillDB(t, s.DB, tf.AddTenants(10), false, tf.AddDefaultNamespaces().State(tenant.Ready))
svc := tenant.NewDBService(s.DB)

// when
Expand All @@ -181,7 +181,7 @@ func (s *TenantServiceTestSuite) TestGetAllTenantsToUpdateBatchByBatch() {
// given
configuration.Commit = "123abc"
testdoubles.SetTemplateVersions()
fxt := tf.FillDB(t, s.DB, 11, false, tf.With().State(tenant.Ready), environment.DefaultEnvTypes...)
fxt := tf.FillDB(t, s.DB, tf.AddTenants(11), false, tf.AddDefaultNamespaces().State(tenant.Ready))
svc := tenant.NewDBService(s.DB)
mappedVersions := testdoubles.GetMappedVersions(environment.DefaultEnvTypes...)

Expand Down Expand Up @@ -264,9 +264,9 @@ func (s *TenantServiceTestSuite) TestGetSubsetOfFailedTenantsToUpdate() {
// given
testdoubles.SetTemplateVersions()
configuration.Commit = "123abc"
previouslyFailed := tf.FillDB(t, s.DB, 1, false, tf.With().State(tenant.Failed), environment.DefaultEnvTypes...)
previouslyFailed := tf.FillDB(t, s.DB, tf.AddTenants(1), false, tf.AddDefaultNamespaces().State(tenant.Failed))
configuration.Commit = "234bcd"
tf.FillDB(t, s.DB, 6, false, tf.With().State(tenant.Failed), environment.DefaultEnvTypes...)
tf.FillDB(t, s.DB, tf.AddTenants(6), false, tf.AddDefaultNamespaces().State(tenant.Failed))

svc := tenant.NewDBService(s.DB)

Expand All @@ -285,8 +285,8 @@ func (s *TenantServiceTestSuite) TestGetSubsetOfTenantsThatAreOutdatedToUpdate()
// given
testdoubles.SetTemplateVersions()
configuration.Commit = "123abc"
outdated := tf.FillDB(t, s.DB, 1, false, tf.With().State(tenant.Ready), environment.DefaultEnvTypes...)
tf.FillDB(t, s.DB, 6, true, tf.With().State(tenant.Ready), environment.DefaultEnvTypes...)
outdated := tf.FillDB(t, s.DB, tf.AddTenants(1), false, tf.AddDefaultNamespaces().State(tenant.Ready))
tf.FillDB(t, s.DB, tf.AddTenants(6), true, tf.AddDefaultNamespaces().State(tenant.Ready))

svc := tenant.NewDBService(s.DB)

Expand All @@ -305,10 +305,10 @@ func (s *TenantServiceTestSuite) TestGetSubsetOfTenantsThatMatchesRequiredCluste
// given
testdoubles.SetTemplateVersions()
configuration.Commit = "123abc"
toBeFound := tf.FillDB(s.T(), s.DB, 1, false,
tf.With().State(tenant.Ready).MasterURL("http://api.cluster1"), environment.DefaultEnvTypes...)
tf.FillDB(s.T(), s.DB, 3, false,
tf.With().State(tenant.Ready).MasterURL("http://api.cluster2"), environment.DefaultEnvTypes...)
toBeFound := tf.FillDB(s.T(), s.DB, tf.AddTenants(1), false,
tf.AddDefaultNamespaces().State(tenant.Ready).MasterURL("http://api.cluster1"))
tf.FillDB(s.T(), s.DB, tf.AddTenants(3), false,
tf.AddDefaultNamespaces().State(tenant.Ready).MasterURL("http://api.cluster2"))

svc := tenant.NewDBService(s.DB)

Expand Down
78 changes: 0 additions & 78 deletions test/data/controller/delete-tenants-204.yaml

This file was deleted.

Loading

0 comments on commit ed78f12

Please sign in to comment.