Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mojtaba/feat-reverse-…
Browse files Browse the repository at this point in the history
…proxy
  • Loading branch information
mojtaba-esk committed May 13, 2024
2 parents 2e5c006 + 7933b89 commit 5b8ecb0
Show file tree
Hide file tree
Showing 30 changed files with 962 additions and 304 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ By participating in this project, you agree to abide by the [CNCF Code of Conduc

See the [Contributing Guide](./CONTRIBUTING.md) for more information.

To ensure that your contribution is working as expected, please run [knuu-example](https://github.com/celestiaorg/knuu-example) with your fork and branch.
To ensure that your contribution is working as expected, please run the tests in the `e2e` folder.

<!---
## Governance
Expand Down
52 changes: 52 additions & 0 deletions e2e/basic/assert_cleanups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package basic

import (
"os"
"testing"

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

// assertCleanupInstance is a helper function that cleans up a single instance.
func assertCleanupInstance(t *testing.T, instance *knuu.Instance) error {
if instance != nil {
err := instance.Destroy()
if err != nil {
t.Fatalf("Error destroying instance: %v", err)
}
}
return nil
}

// assertCleanupInstances is a helper function that cleans up a list of instances.
func assertCleanupInstances(t *testing.T, executor *knuu.Executor, instances []*knuu.Instance) error {
if os.Getenv("KNUU_SKIP_CLEANUP") != "true" {
err := executor.Destroy()
if err != nil {
t.Fatalf("Error destroying executor: %v", err)
}

for _, instance := range instances {
if instance != nil {
err := instance.Destroy()
if err != nil {
t.Fatalf("Error destroying instance: %v", err)
}
}
}
}
return nil
}

// BatchDestroy destroys a list of instances.
func BatchDestroy(instances ...*knuu.Instance) error {
for _, instance := range instances {
if instance != nil {
err := instance.Destroy()
if err != nil {
return err
}
}
}
return nil
}
67 changes: 67 additions & 0 deletions e2e/basic/build_from_git_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package basic

import (
"context"
"os"
"testing"
"time"

"github.com/stretchr/testify/require"

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

// This test is just an example to show how to
// setup the test instance to be built from a git repo
func TestBuildFromGit(t *testing.T) {
t.Parallel()
// Setup

// This code is a bit dirty due to the current limitations of knuu
// After refactoring knuu, this test must be either removed or updated
require.NoError(t, os.Setenv("KNUU_BUILDER", "kubernetes"), "Error setting KNUU_BUILDER Env")
require.NoError(t, knuu.CleanUp(), "Error cleaning up knuu")
require.NoError(t, knuu.Initialize(), "Error initializing knuu")

instance, err := knuu.NewInstance("my-instance")
require.NoError(t, err, "Error creating instance")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

// This is a blocking call which builds the image from git repo
err = instance.SetGitRepo(ctx, builder.GitContext{
Repo: "https://github.com/celestiaorg/celestia-app.git",
Branch: "main",
Commit: "",
Username: "",
Password: "",
})
require.NoError(t, err, "Error setting git repo")

require.NoError(t, instance.SetCommand("sleep", "infinity"), "Error setting command")

err = instance.AddFileBytes([]byte("Hello, world!"), "/home/hello.txt", "root:root")
require.NoError(t, err, "Error adding file")

require.NoError(t, instance.Commit(), "Error committing instance")

t.Cleanup(func() {
if os.Getenv("KNUU_SKIP_CLEANUP") == "true" {
t.Log("Skipping cleanup")
return
}

require.NoError(t, instance.Destroy(), "Error destroying instance")
})

// Test logic

require.NoError(t, instance.Start(), "Error starting instance")

data, err := instance.GetFileBytes("/home/hello.txt")
require.NoError(t, err, "Error getting file bytes")

require.Equal(t, []byte("Hello, world!"), data, "File bytes do not match")
}
17 changes: 3 additions & 14 deletions e2e/basic/file_test_image_cached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,9 @@ func TestFileCached(t *testing.T) {

t.Cleanup(func() {
// Cleanup
if os.Getenv("KNUU_SKIP_CLEANUP") != "true" {
err := executor.Destroy()
if err != nil {
t.Fatalf("Error destroying executor: %v", err)
}

for _, instance := range instances {
if instance != nil {
err := instance.Destroy()
if err != nil {
t.Fatalf("Error destroying instance: %v", err)
}
}
}
err := assertCleanupInstances(t, executor, instances)
if err != nil {
t.Fatalf("Error cleaning up: %v", err)
}
})

Expand Down
Loading

0 comments on commit 5b8ecb0

Please sign in to comment.