Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/google.golang.org/prot…
Browse files Browse the repository at this point in the history
…obuf-1.33.0
  • Loading branch information
tty47 authored Apr 25, 2024
2 parents a0d9d62 + b16351a commit cf5fce4
Show file tree
Hide file tree
Showing 72 changed files with 10,146 additions and 907 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/knuu_testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Knuu Testing

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
test:

runs-on: ubuntu-latest

steps:
- name: Set up Go 1.22.1
uses: actions/setup-go@v4.0.1
with:
go-version: 1.22.1

- name: Check out code into the Go module directory
uses: actions/checkout@v4.1.2

- name: Setup kubeconfig
env:
KUBECONFIG_FILE: ${{ secrets.KNUU_KUBECONFIG_FILE }}
run: |
mkdir -p $HOME/.kube
echo "${KUBECONFIG_FILE}" > $HOME/.kube/config
- name: Run Tests
run: make test-all
env:
KNUU_NAMESPACE: "knuu-test"
KNUU_SKIP_CLEANUP: "false"
KNUU_TIMEOUT: "240m" # needed as we run all the tests
GRAFANA_ENDPOINT: ${{ secrets.GRAFANA_ENDPOINT }}
GRAFANA_USERNAME: ${{ secrets.GRAFANA_USERNAME }}
GRAFANA_TOKEN: ${{ secrets.GRAFANA_TOKEN }}
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
test-basic:
go test -v ./e2e/basic -timeout 120m

test-basic-file-cache:
go test -v ./e2e/basic -run=TestFileCache -count=1 -timeout 120m

test-basic-folder-cache:
go test -v ./e2e/basic -run=TestFolderCache -count=1 -timeout 120m

test-bittwister-packetloss:
KNUU_TIMEOUT=120m go test -v ./e2e/basic --run=TestBittwister_Packetloss -timeout 60m -count=1

test-bittwister-bandwidth:
KNUU_TIMEOUT=120m go test -v ./e2e/basic --run=TestBittwister_Bandwidth -timeout 60m -count=1

test-bittwister-latency:
KNUU_TIMEOUT=120m go test -v ./e2e/basic --run=TestBittwister_Latency -timeout 60m -count=1

test-bittwister-jitter:
KNUU_TIMEOUT=120m go test -v ./e2e/basic --run=TestBittwister_Jitter -timeout 60m -count=1

test-celestia-app:
go test -v ./e2e/celestia_app

test-celestia-node:
go test -v ./e2e/celestia_node

test-all:
KNUU_TIMEOUT=300m go test -v ./e2e/... -timeout 120m

.PHONY: test-all test-basic test-basic-file-cache test-basic-folder-cache test-bittwister-packetloss test-bittwister-bandwidth test-bittwister-latency test-bittwister-jitter test-celestia-app test-celestia-node

100 changes: 86 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# knuu
![knuu-logo](./docs/knuu-logo.png)

![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/celestiaorg/knuu)
![GitHub Release](https://img.shields.io/github/v/release/celestiaorg/knuu)
[![CodeQL](https://github.com/celestiaorg/knuu/workflows/CodeQL/badge.svg)](https://github.com/celestiaorg/knuu/actions) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7475/badge)](https://bestpractices.coreinfrastructure.org/projects/7475)

---

## Description

The goal of knuu is to provide a framework for writing integration tests.
The goal of Knuu is to provide a framework for writing integration tests.
The framework is written in Go and is designed to be used in Go projects.
The idea is to provide a framework that uses the power of containers and Kubernetes without the test writer having to know the details of how to use them.

We invite you to explore our codebase, contribute, and join us in developing a framework to help projects write integration tests.

---

## Features

Knuu is designed around `Instances`, which you can create, start, control, communicate with other Instances, stop, and destroy.

Some of the features of knuu are:
Some of the features of Knuu are:

- Initialize an Instance from a Container/Docker image
- Configure startup commands
Expand All @@ -32,24 +38,25 @@ Some of the features of knuu are:

> If you have feedback on the framework, want to report a bug, or suggest an improvement, please create an issue [here](https://github.com/celestiaorg/knuu/issues/new/choose).
---

## Getting Started

This section will guide you on how to set up and run **knuu**.
This section will guide you on how to set up and run **Knuu**.

### Prerequisites
---

1. **Docker**: Knuu requires Docker to run
> You can install Docker by following the instructions [here](https://docs.docker.com/get-docker/).
### Prerequisites

2. **Kubernetes cluster**: Set up access to a Kubernetes cluster using a kubeconfig.
> In case you have no Kubernets cluster running yet, you can get more information [here](https://kubernetes.io/docs/setup/).
1. **Kubernetes cluster**: Set up access to a Kubernetes cluster using a `kubeconfig`.
> In case you have no Kubernetes cluster running yet, you can get more information [here](https://kubernetes.io/docs/setup/).
3. **'test' Namespace**: Create a namespace called 'test' in your Kubernetes cluster.
> **Note:** The used namespace can be changed by setting the `KNUU_NAMESPACE` environment variable.
2. **Docker**: Knuu uses Docker by default. If `KNUU_BUILDER` is not explicitly set to `kubernetes`, Docker is required to run Knuu.
> You can install Docker by following the instructions [here](https://docs.docker.com/get-docker/).
### Writing Tests

The documentation you can find [here](https://pkg.go.dev/github.com/celestiaorg/knuu).
The documentation you can find [here](https://pkg.go.dev/github.com/celestiaorg/knuu).

Simple example:

Expand All @@ -64,7 +71,7 @@ Simple example:

2. Run `go mod tidy` to download the dependencies.

3. Create a file called `main_test.go` with the following content to initialize knuu:
3. Create a file called `main_test.go` with the following content to initialize Knuu:

```go
package main
Expand Down Expand Up @@ -156,9 +163,11 @@ Simple example:

You can find more examples in the following repositories:

- [celestiaorg/knuu-example](https://github.com/celestiaorg/knuu-example)
- [celestiaorg/knuu](https://github.com/celestiaorg/knuu/e2e)
- [celestiaorg/celestia-app](https://github.com/celestiaorg/celestia-app/tree/main/test/e2e)

---

### Running Tests

You can use the built-in `go test` command to run the tests.
Expand All @@ -169,6 +178,69 @@ To run all tests in the current directory, you can run:
go test -v ./...
```

#### Environment Variables

You can set the following environment variables to change the behavior of knuu:

| Environment Variable | Description | Possible Values | Default |
| --- | --- | --- | --- |
| `KNUU_TIMEOUT` | The timeout for the tests. | Any valid duration | `60m` |
| `KNUU_BUILDER` | The builder to use for building images. | `docker`, `kubernetes` | `docker` |
| `DEBUG_LEVEL` | The debug level. | `debug`, `info`, `warn`, `error` | `info` |

---

# E2E

In the folder `e2e`, you will find some examples of how to use the [knuu](https://github.com/celestiaorg/knuu) Integration Test Framework.

## Setup

1. Install [Docker](https://docs.docker.com/get-docker/).

2. Set up access to a Kubernetes cluster using your `kubeconfig` and create the `test` namespace.

> **Note:** The used namespace can be changed by setting the `KNUU_NAMESPACE` environment variable.

## Write Tests

You can find the relevant documentation in the `pkg/knuu` package at: https://pkg.go.dev/github.com/celestiaorg/knuu

## Run

```shell
make test-all
```

Or run only the basic examples:

```shell
make test-basic
```

Or run BitTwister tests:

```sh
make test-bittwister-packetloss
make test-bittwister-bandwidth
make test-bittwister-latency
make test-bittwister-jitter
```

Or the celestia-app examples:

```shell
make test-celestia-app
```

Or the celestia-node examples:

```shell
make test-celestia-node
```

---

## Contributing

We warmly welcome and appreciate contributions.
Expand Down
Binary file added docs/knuu-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions e2e/basic/basic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package basic

import (
"os"
"testing"

"github.com/stretchr/testify/assert"

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

func TestBasic(t *testing.T) {
t.Parallel()
// Setup

instance, err := knuu.NewInstance("alpine")
if err != nil {
t.Fatalf("Error creating instance '%v':", err)
}
err = instance.SetImage("docker.io/alpine:latest")
if err != nil {
t.Fatalf("Error setting image: %v", err)
}
err = instance.SetCommand("sleep", "infinity")
if err != nil {
t.Fatalf("Error setting command: %v", err)
}
err = instance.Commit()
if err != nil {
t.Fatalf("Error committing instance: %v", err)
}

t.Cleanup(func() {
// Cleanup
if os.Getenv("KNUU_SKIP_CLEANUP") == "true" {
t.Log("Skipping cleanup")
return
}

err = instance.Destroy()
if err != nil {
t.Fatalf("Error destroying instance: %v", err)
}
})

// Test logic

err = instance.Start()
if err != nil {
t.Fatalf("Error starting instance: %v", err)
}
err = instance.WaitInstanceIsRunning()
if err != nil {
t.Fatalf("Error waiting for instance to be running: %v", err)
}
wget, err := instance.ExecuteCommand("echo", "Hello World!")
if err != nil {
t.Fatalf("Error executing command '%v':", err)
}

assert.Equal(t, wget, "Hello World!\n")
}
Loading

0 comments on commit cf5fce4

Please sign in to comment.