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

fix(e2e-523): inital commit - fixing e2e/system tests - WIP #535

Merged
merged 27 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6027c57
fix(e2e-523): inital commit - fixing tests
tty47 Aug 6, 2024
6af8480
fix(e2e-523): inital commit - fixing tests
tty47 Aug 6, 2024
69ff770
fix(e2e-523): inital commit - fixing tests
tty47 Aug 6, 2024
d90ac8f
fix(e2e-523): update s.T().Fatalf to s.Require()
tty47 Aug 7, 2024
872db19
fix(e2e-523): update s.T().Fatalf to s.Require()
tty47 Aug 7, 2024
f99699b
fix(e2e-523): update s.T().Fatalf to s.Require()
tty47 Aug 7, 2024
1dd6415
Merge branch 'main' into jose/test-folders-errors
mojtaba-esk Aug 12, 2024
041d471
chore: conflict resolve & some cleanup
mojtaba-esk Aug 12, 2024
98796b7
fix: linter complains
mojtaba-esk Aug 12, 2024
1bc549f
fix: minio concurrent bucket creation request issue
mojtaba-esk Aug 12, 2024
b2a8e98
fix: map init
mojtaba-esk Aug 12, 2024
03b5b5f
fix: kaniko concurrency overwriting issue
mojtaba-esk Aug 12, 2024
ba23bc9
chore: improve error propagation
mojtaba-esk Aug 13, 2024
8373c9d
fix: image cache issue fixed
mojtaba-esk Aug 16, 2024
845f7a9
fix: failing test suits removed problematic code
mojtaba-esk Aug 19, 2024
cd946d2
chore: increase system test timeout
mojtaba-esk Aug 19, 2024
9039336
chore: fix tests to be executed in parallel
mojtaba-esk Aug 19, 2024
83b02ab
chore: increase timeout to be on the safeside
mojtaba-esk Aug 20, 2024
05f32d1
chore: increase timeout to be on the safeside in the ci
mojtaba-esk Aug 20, 2024
f9d538f
chore: fixed the premature cleanup
mojtaba-esk Aug 20, 2024
29c4bba
chore: testing 60 min timeout
mojtaba-esk Aug 21, 2024
844acfc
fix: the deadlock issue in test suit
mojtaba-esk Aug 21, 2024
50e1ce1
chore: cleanup
mojtaba-esk Aug 21, 2024
6caa339
chore: fixed the missing cleanup
mojtaba-esk Aug 21, 2024
0c14000
chore: applied changes
mojtaba-esk Aug 22, 2024
de3fa64
chore: revert deletion of TestNoVolumesNoFiles
mojtaba-esk Aug 22, 2024
83a204a
Merge branch 'main' into jose/test-folders-errors
mojtaba-esk Aug 27, 2024
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
6 changes: 0 additions & 6 deletions e2e/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ func (ts *TestSuite) TestBasic() {
ts.Require().NoError(target.Build().SetStartCommand("sleep", "infinity"))
ts.Require().NoError(target.Build().Commit(ctx))

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

// Test Logic
ts.Require().NoError(target.Execution().Start(ctx))

Expand Down
33 changes: 0 additions & 33 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 @@ -47,14 +46,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 Expand Up @@ -156,14 +147,6 @@ func (s *Suite) TestNetShaperPacketloss() {
executor, err := mother.CloneWithName("executor")
s.Require().NoError(err)

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

// Prepare ping executor & target

s.Require().NoError(target.Execution().Start(ctx))
Expand Down Expand Up @@ -259,14 +242,6 @@ func (s *Suite) TestNetShaperLatency() {
executor, err := mother.CloneWithName("executor")
s.Require().NoError(err)

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

// Prepare ping executor & target

s.Require().NoError(target.Execution().Start(ctx))
Expand Down Expand Up @@ -369,14 +344,6 @@ func (s *Suite) TestNetShaperJitter() {
executor, err := mother.CloneWithName("executor")
s.Require().NoError(err)

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

// Prepare ping executor & target

s.Require().NoError(target.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
90 changes: 50 additions & 40 deletions e2e/system/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,73 @@ 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)
if err != nil {
s.Require().NoError(err, "Error creating executor instance")
}
mojtaba-esk marked this conversation as resolved.
Show resolved Hide resolved

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.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.Require().NoError(serverfile.Build().Commit(ctx))

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 +85,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 +107,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 +117,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
Loading