Skip to content

Commit

Permalink
Merge pull request #66 from nokia/improve-e2e
Browse files Browse the repository at this point in the history
Minor improvements to end-to-end testing framework
  • Loading branch information
nephio-prow[bot] authored Jun 7, 2024
2 parents 2faaa8b + eb40bcb commit ef6badd
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 159 deletions.
9 changes: 7 additions & 2 deletions scripts/clean-kind-only-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ PORCH_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
cd $PORCH_DIR

kind_cluster="porch-e2e"
kubeconfig_file="$(mktemp)"

kind delete cluster --name "$kind_cluster" || true
kind create cluster --name "$kind_cluster"
make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME="$kind_cluster" KUBECONFIG="$(kind get kubeconfig --name "$kind_cluster")"
kind get kubeconfig --name "$kind_cluster" > "$kubeconfig_file"
make run-in-kind-kpt IMAGE_TAG='test' KIND_CONTEXT_NAME="$kind_cluster" KUBECONFIG="$kubeconfig_file"
for deployment in porch-controllers porch-server function-runner; do
kubectl rollout status deployment $deployment --namespace porch-system
kubectl wait --namespace porch-system deploy $deployment \
Expand All @@ -42,4 +44,7 @@ echo "--- test/e2e ---"
E2E=1 go test -failfast -v ./test/e2e
echo "--- test/e2e/cli ---"
E2E=1 go test -failfast -v ./test/e2e/cli
echo "--- leaving e2e kind cluster $kind_cluster up for debugging ---"
echo "--- deleting kind cluster that is dedicated for clean end-to-end tests ($kind_cluster) ---"
kind delete cluster --name "$kind_cluster" || true

rm -f "$kubeconfig_file"
94 changes: 1 addition & 93 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,99 +83,6 @@ func Run(suite interface{}, t *testing.T) {
})
}

type PorchSuite struct {
TestSuite
gitConfig GitConfig
}

var _ Initializer = &PorchSuite{}

func (p *PorchSuite) Initialize(ctx context.Context) {
p.TestSuite.Initialize(ctx)
p.gitConfig = p.CreateGitRepo()
}

func (p *PorchSuite) GitConfig(repoID string) GitConfig {
config := p.gitConfig
config.Repo = config.Repo + "/" + repoID
return config
}

func (t *PorchSuite) registerMainGitRepositoryF(ctx context.Context, name string, opts ...repositoryOption) {
repoID := t.namespace + "-" + name
config := t.GitConfig(repoID)

var secret string
// Create auth secret if necessary
if config.Username != "" || config.Password != "" {
secret = fmt.Sprintf("%s-auth", name)
immutable := true
t.CreateF(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secret,
Namespace: t.namespace,
},
Immutable: &immutable,
Data: map[string][]byte{
"username": []byte(config.Username),
"password": []byte(config.Password),
},
Type: corev1.SecretTypeBasicAuth,
})
t.Cleanup(func() {
t.DeleteE(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: secret,
Namespace: t.namespace,
},
})
})
}

repository := &configapi.Repository{
TypeMeta: metav1.TypeMeta{
Kind: "Repository",
APIVersion: configapi.GroupVersion.Identifier(),
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: t.namespace,
},
Spec: configapi.RepositorySpec{
Description: "Porch Test Repository Description",
Type: configapi.RepositoryTypeGit,
Content: configapi.RepositoryContentPackage,
Git: &configapi.GitRepository{
Repo: config.Repo,
Branch: config.Branch,
Directory: config.Directory,
SecretRef: configapi.SecretRef{
Name: secret,
},
},
},
}

// Apply options
for _, o := range opts {
o(repository)
}

// Register repository
t.CreateF(ctx, repository)

t.Cleanup(func() {
t.DeleteE(ctx, &configapi.Repository{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: t.namespace,
},
})
t.waitUntilRepositoryDeleted(ctx, name, t.namespace)
t.waitUntilAllPackagesDeleted(ctx, name)
})
}

func (t *PorchSuite) TestGitRepository(ctx context.Context) {
// Register the repository as 'git'
t.registerMainGitRepositoryF(ctx, "git")
Expand Down Expand Up @@ -846,6 +753,7 @@ func (t *PorchSuite) TestFunctionRepository(ctx context.Context) {
// the sync has (hopefully) finished.
// TODO(mortent): We need a better solution for this. This is only
// temporary to fix the current flakiness with the e2e tests.
t.Log("Waiting for 2 minutes for the repository to be cached")
<-time.NewTimer(2 * time.Minute).C

list := &porchapi.FunctionList{}
Expand Down
Loading

0 comments on commit ef6badd

Please sign in to comment.