-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into mojtaba/feat-reverse-…
…proxy
- Loading branch information
Showing
30 changed files
with
962 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.