dockertest

package module
v0.0.0-...-e1b74f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 5 Imported by: 0

README

testing-with-docker

方便在 Go 项目中使用 Docker 对存储层运行测试

go versions

>=1.20

usage

下载安装:go get github.com/udugong/testing-with-docker@latest

生成 docker 相关项

目前提供了以下的使用方式:

本地 Docker

连接本地的 Docker 来启动相应镜像的容器

import "github.com/udugong/testing-with-docker"

// 该方法提供了一个本地 Docker item 的生成器
dockertest.NewLocalDockerItem()

SSH 远程 Docker

使用 SSH 协议连接远程的 Docker 来启动相应镜像的容器。

注意:

  1. 远程主机需要开放 22 端口
  2. 需要配置 ssh 免密钥登录
  3. 使用该方式需要远程主机的 Docker 版本 >=18.09
import "github.com/udugong/testing-with-docker"

// 该方法提供了一个远程 Docker item 的生成器
dockertest.NewSSHDockerItem("ssh://<user>@<host>") // 例如 ssh://ubuntu@192.168.1.2

gorm package

该包可以根据相应数据库镜像启动对应的容器,并且提供初始化 *gorm.DB 的方法。使用方法参考 mysqlpostgres

mongo package

该包可以启动 mongodb 的容器,并且提供初始化 *mongo.Client 的方法。使用方法参考 mongo

redis package

该包可以启动 redis 的容器,并且提供初始化 *redis.Client 的方法。使用方法参考 redis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DockerClientFromSSH

func DockerClientFromSSH(daemonURL string) (*client.Client, error)

DockerClientFromSSH Obtain the Docker client through SSH.

Types

type DockerItemGenerator

type DockerItemGenerator interface {
	Generate() (cli *client.Client, hostIP string, bindingIP string)
}

type LocalDockerItem

type LocalDockerItem struct{}

func NewLocalDockerItem

func NewLocalDockerItem() *LocalDockerItem

func (*LocalDockerItem) Generate

func (l *LocalDockerItem) Generate() (cli *client.Client, hostIP string, bindingIP string)

type SSHDockerItem

type SSHDockerItem struct {
	// DaemonURL ssh://<user>@<host> URL requires Docker 18.09 or later on the remote host.
	DaemonURL string
}

func NewSSHDockerItem

func NewSSHDockerItem(daemonURL string) *SSHDockerItem

func (*SSHDockerItem) Generate

func (d *SSHDockerItem) Generate() (cli *client.Client, hostIP string, bindingIP string)

Directories

Path Synopsis
gorm

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL