-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad86999
commit 1ccc809
Showing
20 changed files
with
671 additions
and
261 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package system | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"time" | ||
|
||
"github.com/celestiaorg/knuu/pkg/builder" | ||
"github.com/celestiaorg/knuu/pkg/instance" | ||
) | ||
|
||
const ( | ||
gitRepo = "https://github.com/celestiaorg/knuu.git" | ||
gitBranch = "test/build-from-git" // This branch has a Dockerfile and is protected as to not be deleted | ||
) | ||
|
||
func (s *Suite) TestBuildFromGit() { | ||
const namePrefix = "registry-build-from-git" | ||
|
||
// Setup | ||
ctx := context.Background() | ||
|
||
target, err := s.createAndStartBuildFromGitInstance(ctx, namePrefix) | ||
s.Require().NoError(err) | ||
|
||
s.T().Log("Getting file bytes") | ||
// The file is created by the dockerfile in the repo, | ||
// so to make sure it is built correctly, we check the file | ||
data, err := target.Storage().GetFileBytes(ctx, "/test.txt") | ||
s.Require().NoError(err) | ||
|
||
data = []byte(strings.TrimSpace(string(data))) | ||
s.Assert().Equal([]byte("Hello, World!"), data, "file bytes do not match.") | ||
} | ||
|
||
func (s *Suite) TestRegistryCacheWithBuildFromGit() { | ||
const namePrefix = "cache-registry-build-from-git" | ||
|
||
// Setup | ||
ctx := context.Background() | ||
|
||
_, err := s.createAndStartBuildFromGitInstance(ctx, namePrefix) | ||
s.Require().NoError(err) | ||
|
||
startTime := time.Now() | ||
|
||
_, err = s.createAndStartBuildFromGitInstance(ctx, "2nd-"+namePrefix) | ||
s.Require().NoError(err) | ||
|
||
duration := time.Since(startTime) | ||
s.T().Logf("Time taken: %s", duration) | ||
} | ||
|
||
func (s *Suite) createAndStartBuildFromGitInstance(ctx context.Context, namePrefix string) (*instance.Instance, error) { | ||
s.T().Logf("Creating new instance %s", namePrefix) | ||
target, err := s.Knuu.NewInstance(namePrefix) | ||
s.Require().NoError(err) | ||
|
||
s.T().Log("Building the image") | ||
|
||
// This is a blocking call which builds the image from git repo | ||
err = target.Build().SetGitRepo(ctx, builder.GitContext{ | ||
Repo: gitRepo, | ||
Branch: gitBranch, | ||
Username: "", | ||
Password: "", | ||
}) | ||
s.Require().NoError(err) | ||
s.T().Log("Image built") | ||
|
||
s.Require().NoError(target.Build().Commit(ctx)) | ||
|
||
s.T().Logf("Starting instance %s", namePrefix) | ||
s.Require().NoError(target.Execution().Start(ctx)) | ||
|
||
s.T().Log("Instance started") | ||
return target, 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,56 @@ | ||
package system | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/celestiaorg/knuu/e2e" | ||
"github.com/celestiaorg/knuu/pkg/k8s" | ||
"github.com/celestiaorg/knuu/pkg/knuu" | ||
"github.com/celestiaorg/knuu/pkg/minio" | ||
) | ||
|
||
const ( | ||
testTimeout = time.Minute * 100 // the same time that is used in the ci/cd pipeline | ||
alpineImage = "alpine:latest" | ||
) | ||
|
||
type Suite struct { | ||
e2e.Suite | ||
} | ||
|
||
func TestRunSuite(t *testing.T) { | ||
suite.Run(t, new(Suite)) | ||
} | ||
|
||
func (s *Suite) SetupSuite() { | ||
var ( | ||
ctx = context.Background() | ||
logger = logrus.New() | ||
) | ||
|
||
logger.SetLevel(logrus.DebugLevel) | ||
|
||
k8sClient, err := k8s.NewClient(ctx, knuu.DefaultScope(), logger) | ||
s.Require().NoError(err, "Error creating k8s client") | ||
|
||
minioClient, err := minio.New(ctx, k8sClient, logger) | ||
s.Require().NoError(err, "Error creating minio client") | ||
|
||
s.Knuu, err = knuu.New(ctx, knuu.Options{ | ||
LocalRegistryEnabled: true, | ||
K8sClient: k8sClient, | ||
MinioClient: minioClient, // needed for build from git tests | ||
Timeout: testTimeout, | ||
}) | ||
s.Require().NoError(err) | ||
|
||
s.T().Logf("Scope: %s", s.Knuu.Scope) | ||
s.Knuu.HandleStopSignal(ctx) | ||
|
||
s.Executor.Kn = s.Knuu | ||
} |
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
Oops, something went wrong.