Skip to content

Commit

Permalink
chore!: removing the loadEnvVars func (#503)
Browse files Browse the repository at this point in the history
* chore: Deploy timeout-handler before traefik and minio

* chore: removing the loadEnvVars func

* chore: rename TestScope field (#504)

* chore: docs updated

* chore: bump go and k8s version to fix the DOS Vulnerability (#506)

* chore: rename TestScope field

* chore: bump k8s version to fix the DOS Vulnerability

* chore: bumped go version to fix it

* chore!: remove Executor from knuu (#508)

* chore: rename TestScope field

* chore: bump k8s version to fix the DOS Vulnerability

* chore: bumped go version to fix it

* chore: deprecate Executor

* fix: rename the deprecated NewExecutor

* chore: refactor e2e system tests to new knuu obj (#520)

* chore: refactor system e2e tests to new knuu obj

* fix: added missing commit before start

* fix: added missing commit before start

* fix: added missing commit before start

* chore: code cleanup

* chore: some more cleanup

* fix: a typo in err var
  • Loading branch information
mojtaba-esk authored Jul 24, 2024
1 parent 057c341 commit 2da9172
Show file tree
Hide file tree
Showing 36 changed files with 661 additions and 1,003 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ You can set the following environment variables to change the behavior of knuu:

| Environment Variable | Description | Possible Values | Default |
| --- | --- | --- | --- |
| `KNUU_TIMEOUT` | The timeout for the tests. | Any valid duration | `60m` |
| `KNUU_BUILDER` | The builder to use for building images. | `docker`, `kubernetes` | `docker` |
| `LOG_LEVEL` | The debug level. | `debug`, `info`, `warn`, `error` | `info` |

**Note:** `knuu` does not load `.env` file, if you want to set environment variables, you can set them directly in the code or use a `.env` file and load it using `go-dotenv`.

---

# E2E
Expand Down
43 changes: 0 additions & 43 deletions e2e/assert_cleanups.go

This file was deleted.

55 changes: 0 additions & 55 deletions e2e/assert_create.go

This file was deleted.

24 changes: 20 additions & 4 deletions e2e/basic/probe_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package basic

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/celestiaorg/knuu/e2e"
"github.com/celestiaorg/knuu/pkg/knuu"
)

func TestProbe(t *testing.T) {
t.Parallel()
// Setup

executor, err := knuu.NewExecutor()
// Ideally this has to be defined in the test suit setup
exe := e2e.Executor{
Kn: knuu.GetKnuuObj(),
}

ctx := context.Background()
executor, err := exe.NewInstance(ctx, "prob-executor")
if err != nil {
t.Fatalf("Error creating executor: %v", err)
}
Expand Down Expand Up @@ -60,7 +67,16 @@ func TestProbe(t *testing.T) {
}

t.Cleanup(func() {
require.NoError(t, knuu.BatchDestroy(executor.Instance, web))
// after refactor, we can use instance.BatchDestroy for simplicity
err := executor.Destroy(ctx)
if err != nil {
t.Logf("Error destroying instance: %v", err)
}

err = web.Destroy()
if err != nil {
t.Logf("Error destroying instance: %v", err)
}
})

// Test logic
Expand All @@ -79,7 +95,7 @@ func TestProbe(t *testing.T) {
t.Fatalf("Error waiting for instance to be running: %v", err)
}

wget, err := executor.ExecuteCommand("wget", "-q", "-O", "-", webIP)
wget, err := executor.ExecuteCommand(ctx, "wget", "-q", "-O", "-", webIP)
if err != nil {
t.Fatalf("Error executing command '%v':", err)
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *TestSuite) SetupSuite() {
ctx = context.Background()
)
s.Knuu, err = knuu.New(ctx, knuu.Options{
TestScope: "e2e-basic",
Scope: "e2e-basic",
})
s.Require().NoError(err)
s.Knuu.HandleStopSignal(ctx)
Expand Down
2 changes: 1 addition & 1 deletion e2e/bittwister/suite_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *Suite) SetupSuite() {
ProxyEnabled: true,
})
s.Require().NoError(err)
s.T().Logf("Scope: %s", s.Knuu.Scope())
s.T().Logf("Scope: %s", s.Knuu.Scope)
s.Knuu.HandleStopSignal(ctx)
}

Expand Down
35 changes: 17 additions & 18 deletions pkg/instance/executor.go → e2e/executor.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
package instance
package e2e

import (
"context"

"k8s.io/apimachinery/pkg/api/resource"

"github.com/celestiaorg/knuu/pkg/system"
"github.com/celestiaorg/knuu/pkg/instance"
"github.com/celestiaorg/knuu/pkg/knuu"
)

const (
executorDefaultImage = "docker.io/nicolaka/netshoot:latest"
executorName = "executor"
sleepCommand = "sleep"
infinityArg = "infinity"
)

type Executor struct {
Kn *knuu.Knuu
}

var (
executorMemoryLimit = resource.MustParse("100Mi")
executorCpuLimit = resource.MustParse("100m")
)

type Executor struct {
*Instance
}

func NewExecutor(ctx context.Context, sysDeps system.SystemDependencies) (*Executor, error) {
i, err := New(executorName, sysDeps)
func (e *Executor) NewInstance(ctx context.Context, name string) (*instance.Instance, error) {
i, err := e.Kn.NewInstance(name)
if err != nil {
return nil, ErrCreatingInstance.Wrap(err)
return nil, err
}

if err := i.SetImage(ctx, executorDefaultImage); err != nil {
return nil, ErrSettingImage.Wrap(err)
return nil, err
}

if err := i.Commit(); err != nil {
return nil, ErrCommittingInstance.Wrap(err)
return nil, err
}

if err := i.SetArgs(sleepCommand, infinityArg); err != nil {
return nil, ErrSettingArgs.Wrap(err)
return nil, err
}

if err := i.SetMemory(executorMemoryLimit, executorMemoryLimit); err != nil {
return nil, ErrSettingMemory.Wrap(err)
return nil, err
}

if err := i.SetCPU(executorCpuLimit); err != nil {
return nil, ErrSettingCPU.Wrap(err)
return nil, err
}
i.instanceType = ExecutorInstance

if err := i.Start(ctx); err != nil {
return nil, ErrStartingInstance.Wrap(err)
return nil, err
}

return &Executor{Instance: i}, nil
return i, nil
}
Loading

0 comments on commit 2da9172

Please sign in to comment.