Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add build from git example test #314

Merged
merged 4 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved

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")
}
Loading