195 lines
3.2 KiB
Go
195 lines
3.2 KiB
Go
|
package glue
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"os"
|
||
|
"path"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/jinzhu/gorm"
|
||
|
"github.com/rosti-cz/node-api/apps"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
|
||
|
// This is line from GORM documentation that imports database dialect
|
||
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||
|
)
|
||
|
|
||
|
const testDBPath = "file::memory:?cache=shared"
|
||
|
|
||
|
var testAppTemplate apps.App = apps.App{
|
||
|
Name: "test_1234",
|
||
|
SSHPort: 10000,
|
||
|
HTTPPort: 10001,
|
||
|
Image: "harbor.hq.rosti.cz/public/runtime:2022.01-1",
|
||
|
CPU: 50,
|
||
|
Memory: 256,
|
||
|
}
|
||
|
|
||
|
func getPWD() string {
|
||
|
dir, err := os.Getwd()
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
return dir
|
||
|
}
|
||
|
|
||
|
func testDB() *gorm.DB {
|
||
|
db, err := gorm.Open("sqlite3", testDBPath)
|
||
|
if err != nil {
|
||
|
log.Fatalln(err)
|
||
|
}
|
||
|
|
||
|
return db
|
||
|
}
|
||
|
|
||
|
func getTestDockerSock() string {
|
||
|
dockerSocket := os.Getenv("DOCKER_SOCKET")
|
||
|
if dockerSocket == "" {
|
||
|
return "unix:///run/user/1000/podman/podman.sock"
|
||
|
}
|
||
|
return dockerSocket
|
||
|
}
|
||
|
|
||
|
var processor Processor
|
||
|
|
||
|
func TestMain(m *testing.M) {
|
||
|
// This processor is used to test all methods
|
||
|
processor = Processor{
|
||
|
AppName: testAppTemplate.Name,
|
||
|
DB: testDB(),
|
||
|
// SnapshotProcessor *apps.SnapshotProcessor
|
||
|
DockerSock: getTestDockerSock(),
|
||
|
BindIPHTTP: "127.0.0.1",
|
||
|
BindIPSSH: "127.0.0.1",
|
||
|
AppsPath: path.Join(getPWD(), "tmp/apps"),
|
||
|
}
|
||
|
|
||
|
exitVal := m.Run()
|
||
|
|
||
|
// We don't care about output here because we can't do anything about it
|
||
|
//! If testing fails and this won't be performed you have to remove the test container manually
|
||
|
fmt.Println("Removing test container")
|
||
|
processor.Delete()
|
||
|
|
||
|
os.Exit(exitVal)
|
||
|
}
|
||
|
|
||
|
func TestProcessorCreate(t *testing.T) {
|
||
|
err := processor.Create(testAppTemplate)
|
||
|
assert.Nil(t, err)
|
||
|
processor.Delete()
|
||
|
assert.Nil(t, err)
|
||
|
}
|
||
|
|
||
|
func TestProcessorList(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorGet(t *testing.T) {
|
||
|
err := processor.Create(testAppTemplate)
|
||
|
assert.Nil(t, err)
|
||
|
|
||
|
app, err := processor.Get()
|
||
|
assert.Nil(t, err)
|
||
|
fmt.Println("State", app.State)
|
||
|
|
||
|
processor.Delete()
|
||
|
assert.Nil(t, err)
|
||
|
}
|
||
|
|
||
|
func TestProcessorRegister(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorUpdate(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorDelete(t *testing.T) {
|
||
|
err := processor.Create(testAppTemplate)
|
||
|
assert.Nil(t, err)
|
||
|
processor.Delete()
|
||
|
assert.Nil(t, err)
|
||
|
}
|
||
|
|
||
|
func TestProcessorStop(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorStart(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorRestart(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorUpdateKeys(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorSetPassword(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorProcesses(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorEnableTech(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorRebuild(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorAddLabel(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorRemoveLabel(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorGetNode(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorCreateSnapshot(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorRestoreFromSnapshot(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorListSnapshots(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorListAppsSnapshots(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorListSnapshotsByLabel(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorGetSnapshot(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorGetSnapshotDownloadLink(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorDeleteSnapshot(t *testing.T) {
|
||
|
|
||
|
}
|
||
|
|
||
|
func TestProcessorDeleteAppSnapshots(t *testing.T) {
|
||
|
|
||
|
}
|