Skip to content

Commit

Permalink
fix(e2e-523): inital commit - fixing e2e/system tests - WIP (#535)
Browse files Browse the repository at this point in the history
* fix(e2e-523): inital commit - fixing tests

Signed-off-by: Jose Ramon Mañes <[email protected]>

* fix(e2e-523): inital commit - fixing tests

Signed-off-by: Jose Ramon Mañes <[email protected]>

* fix(e2e-523): inital commit - fixing tests

Signed-off-by: Jose Ramon Mañes <[email protected]>

* fix(e2e-523): update s.T().Fatalf to  s.Require()

Signed-off-by: Jose Ramon Mañes <[email protected]>

* fix(e2e-523): update s.T().Fatalf to  s.Require()

Signed-off-by: Jose Ramon Mañes <[email protected]>

* fix(e2e-523): update s.T().Fatalf to  s.Require()

Signed-off-by: Jose Ramon Mañes <[email protected]>

* chore: conflict resolve & some cleanup

* fix: linter complains

* fix: minio concurrent bucket creation request issue

* fix: map init

* fix: kaniko concurrency overwriting issue

* chore: improve error propagation

* fix: image cache issue fixed

* fix: failing test suits removed problematic code

* chore: increase system test timeout

* chore: fix tests to be executed in parallel

* chore: increase timeout to be on the safeside

* chore: increase timeout to be on the safeside in the ci

* chore: fixed the premature cleanup

* chore: testing 60 min timeout

* fix: the deadlock issue in test suit

* chore: cleanup

* chore: fixed the missing cleanup

* chore: applied changes

* chore: revert deletion of TestNoVolumesNoFiles

---------

Signed-off-by: Jose Ramon Mañes <[email protected]>
Co-authored-by: Mojtaba <[email protected]>
Co-authored-by: Moji <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 96ba8ca commit fbf0fb1
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 306 deletions.
9 changes: 0 additions & 9 deletions e2e/netshaper/netshaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strconv"
"time"

"github.com/celestiaorg/knuu/pkg/instance"
"github.com/celestiaorg/knuu/pkg/sidecars/netshaper"
)

Expand Down Expand Up @@ -45,14 +44,6 @@ func (s *Suite) TestNetShaperBandwidth() {
btSidecar := netshaper.New()
s.Require().NoError(iperfServer.Sidecars().Add(ctx, btSidecar))

s.T().Cleanup(func() {
s.T().Log("Tearing down TestNetShaperBandwidth test...")
err := instance.BatchDestroy(ctx, iperfServer, iperfClient)
if err != nil {
s.T().Logf("error destroying instances: %v", err)
}
})

// Prepare iperf client & server

s.Require().NoError(iperfServer.Execution().Start(ctx))
Expand Down
75 changes: 40 additions & 35 deletions e2e/system/build_from_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,85 +7,90 @@ import (
"github.com/celestiaorg/knuu/pkg/builder"
)

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 = "build-from-git"
s.T().Parallel()

// Setup
ctx := context.Background()

s.T().Log("Creating new instance")
target, err := s.Knuu.NewInstance(namePrefix)
s.Require().NoError(err)
s.Require().NoError(err, "Error creating new instance")

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: "https://github.com/celestiaorg/knuu.git",
Branch: "test/build-from-git", // This branch has a Dockerfile and is protected as to not be deleted
Repo: gitRepo,
Branch: gitBranch,
Username: "",
Password: "",
})
s.Require().NoError(err)

s.Require().NoError(err, "Error setting git repo")
s.T().Log("Image built")

s.T().Cleanup(func() {
if err := target.Execution().Destroy(ctx); err != nil {
s.T().Logf("Error cleaning up knuu: %v", err)
}
})

s.Require().NoError(target.Build().Commit(ctx))

s.T().Logf("Starting instance")
s.Require().NoError(target.Execution().Start(ctx))

s.T().Logf("Instance started")
s.T().Log("Instance started")

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")
s.Assert().Equal([]byte("Hello, World!"), data, "file bytes do not match.")
}

func (s *Suite) TestBuildFromGitWithModifications() {
const namePrefix = "build-from-git-with-modifications"
s.T().Parallel()
const (
namePrefix = "build-from-git-with-modifications"
maxRetries = 3
)

// Setup
ctx := context.Background()

s.T().Log("Creating new instance")
target, err := s.Knuu.NewInstance(namePrefix)
s.Require().NoError(err)

ctx := context.Background()
// This is a blocking call which builds the image from git repo
err = target.Build().SetGitRepo(ctx, builder.GitContext{
Repo: "https://github.com/celestiaorg/knuu.git",
Branch: "test/build-from-git", // This branch has a Dockerfile and is protected as to not be deleted
Username: "",
Password: "",
})
s.T().Log("Setting git repo")
err = s.retryOperation(func() error {
return target.Build().SetGitRepo(ctx, builder.GitContext{
Repo: gitRepo,
Branch: gitBranch,
Username: "",
Password: "",
})
}, maxRetries)
s.Require().NoError(err)

s.Require().NoError(target.Build().SetStartCommand("sleep", "infinity"))

err = target.Storage().AddFileBytes([]byte("Hello, world!"), "/home/hello.txt", "root:root")
s.Require().NoError(err, "Error adding file")
const (
filePath = "/home/hello.txt"
expectedData = "Hello, world!"
)

s.Require().NoError(target.Build().Commit(ctx))
err = target.Storage().AddFileBytes([]byte(expectedData), filePath, "root:root")
s.Require().NoError(err)

s.T().Cleanup(func() {
if err := target.Execution().Destroy(ctx); err != nil {
s.T().Logf("Error cleaning up knuu: %v", err)
}
})
s.Require().NoError(target.Build().Commit(ctx))

s.Require().NoError(target.Execution().Start(ctx))

data, err := target.Storage().GetFileBytes(ctx, "/home/hello.txt")
s.Require().NoError(err, "Error getting file bytes")
gotData, err := target.Storage().GetFileBytes(ctx, filePath)
s.Require().NoError(err)

s.Assert().Equal([]byte("Hello, world!"), data, "File bytes do not match")
s.Assert().Equal([]byte(expectedData), gotData, "file bytes do not match.")
}
10 changes: 0 additions & 10 deletions e2e/system/env_to_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ func (s *Suite) TestEnvToJSON() {
numberOfInstances = 2
)

s.T().Parallel()

// Setup
ctx := context.Background()
executor, err := s.Executor.NewInstance(ctx, namePrefix+"-executor")
Expand Down Expand Up @@ -61,14 +59,6 @@ func (s *Suite) TestEnvToJSON() {
instances[i] = ins
}

s.T().Cleanup(func() {
all := append(instances, executor)
err := instance.BatchDestroy(ctx, all...)
if err != nil {
s.T().Logf("error destroying instances: %v", err)
}
})

// Test logic
for _, i := range instances {
webIP, err := i.Network().GetIP(ctx)
Expand Down
10 changes: 0 additions & 10 deletions e2e/system/external_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"io"
"os"
"path/filepath"

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

func (s *Suite) TestExternalFile() {
const namePrefix = "external-file"
s.T().Parallel()
// Setup

ctx := context.Background()
Expand Down Expand Up @@ -43,13 +40,6 @@ func (s *Suite) TestExternalFile() {

s.Require().NoError(server.Build().Commit(ctx))

s.T().Cleanup(func() {
err := instance.BatchDestroy(ctx, executor, server)
if err != nil {
s.T().Logf("error destroying instance: %v", err)
}
})

// Test logic
serverIP, err := server.Network().GetIP(ctx)
s.Require().NoError(err)
Expand Down
86 changes: 47 additions & 39 deletions e2e/system/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,71 @@ import (
"os"
"time"

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

"github.com/google/uuid"
)

func (s *Suite) TestFile() {
const namePrefix = "file"
s.T().Parallel()
// Setup
const (
namePrefix = "file"
maxRetries = 3
)

// Setup
ctx := context.Background()

s.T().Log("Creating executor instance")
executor, err := s.Executor.NewInstance(ctx, namePrefix+"-executor")
s.Require().NoError(err)

s.T().Log("Creating nginx instance with volume")
serverfile := s.createNginxInstanceWithVolume(ctx, namePrefix+"-serverfile")

err = serverfile.Storage().AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
s.Require().NoError(err)

s.Require().NoError(serverfile.Build().Commit(ctx))
s.T().Log("Adding file to nginx instance")
err = s.retryOperation(func() error {
return serverfile.Storage().AddFile(resourcesHTML+"/index.html", nginxHTMLPath+"/index.html", "0:0")
}, maxRetries)
s.Require().NoError(err, "Error adding file to nginx instance")

s.T().Cleanup(func() {
err := instance.BatchDestroy(ctx, serverfile, executor)
if err != nil {
s.T().Logf("Error destroying instance: %v", err)
}
})
s.T().Log("Committing changes")
err = s.retryOperation(func() error {
return serverfile.Build().Commit(ctx)
}, maxRetries)
s.Require().NoError(err, "Error committing changes")

// Test logic

serverfileIP, err := serverfile.Network().GetIP(ctx)
s.Require().NoError(err)

s.Require().NoError(serverfile.Execution().Start(ctx))

wget, err := executor.Execution().ExecuteCommand(ctx, "wget", "-q", "-O", "-", serverfileIP)
s.Require().NoError(err)

s.T().Log("Getting server IP")
var serverfileIP string
err = s.retryOperation(func() error {
var err error
serverfileIP, err = serverfile.Network().GetIP(ctx)
return err
}, maxRetries)
s.Require().NoError(err, "Error getting server IP")

s.T().Log("Starting server")
err = s.retryOperation(func() error {
return serverfile.Execution().Start(ctx)
}, maxRetries)
s.Require().NoError(err, "Error starting server")

s.T().Log("Executing wget command")
var wget string
err = s.retryOperation(func() error {
var err error
wget, err = executor.Execution().ExecuteCommand(ctx, "wget", "-q", "-O", "-", serverfileIP)
return err
}, maxRetries)
s.Require().NoError(err, "Error executing wget command")

s.T().Log("Asserting wget output")
s.Assert().Contains(wget, "Hello World!")
}

func (s *Suite) TestDownloadFileFromRunningInstance() {
const namePrefix = "download-file-running"
s.T().Parallel()
const (
namePrefix = "download-file-running"
)

// Setup

target, err := s.Knuu.NewInstance(namePrefix + "-target")
Expand All @@ -62,12 +83,6 @@ func (s *Suite) TestDownloadFileFromRunningInstance() {
s.Require().NoError(target.Build().Commit(ctx))
s.Require().NoError(target.Execution().Start(ctx))

s.T().Cleanup(func() {
if err := target.Execution().Destroy(ctx); err != nil {
s.T().Logf("error destroying instance: %v", err)
}
})

// Test logic
const (
fileContent = "Hello World!"
Expand All @@ -90,7 +105,6 @@ func (s *Suite) TestMinio() {
minioBucketName = "knuu-e2e-test"
minioPushTimeout = 1 * time.Minute
)
s.T().Parallel()
// Setup
target, err := s.Knuu.NewInstance(namePrefix + "-target")
s.Require().NoError(err)
Expand All @@ -101,12 +115,6 @@ func (s *Suite) TestMinio() {
s.Require().NoError(target.Build().Commit(ctx))
s.Require().NoError(target.Execution().Start(ctx))

s.T().Cleanup(func() {
if err := target.Execution().Destroy(ctx); err != nil {
s.T().Logf("error destroying instance: %v", err)
}
})

var (
fileContent = "Hello World!"
contentName = uuid.New().String()
Expand Down
Loading

0 comments on commit fbf0fb1

Please sign in to comment.