test

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 33 Imported by: 0

README

test

PkgGoDev

Use gitea for testing git logic.

Usage

package main_test

import (
	"context"
	"testing"
	"time"

	"github.com/gitmirrorer/test"
	"github.com/stretchr/testify/require"
	"golang.org/x/crypto/ssh"
)

func TestClone(t *testing.T) {
	ctx := context.Background()
	server, err := test.ListenAndServe(ctx, "")
	require.NoError(t, err)
	defer server.Close(ctx)

	prep, err := test.PrepareRepositoriesOnAServer(
		context.Background(),
		server,
		t.Name(),
		map[string]string{
			"file1.txt": "File 1 Contents",
		},
		map[string]string{
			"file2.txt": "File 2 Contents",
		},
	)
	require.NoError(t, err)
	defer prep.Close(ctx)

	// work with the repositories
	// Clone(prep.Source.HTTP.URL)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Git gitImpl

Functions

func CreateBasicAuthHeaderValue

func CreateBasicAuthHeaderValue(username, password string) string

func CreatePrivateSSHKey

func CreatePrivateSSHKey(bitSize int) (privateKeyInPEM, authorizedKeys []byte, err error)

func GeneratePrivateRSAKey

func GeneratePrivateRSAKey(bitSize int) (*rsa.PrivateKey, error)

func GetPublicKeyForServer

func GetPublicKeyForServer(host string) (ssh.PublicKey, error)

Types

type HTTPConfig

type HTTPConfig struct {
	URL    string
	Header map[string]string
}

type Preparation

type Preparation struct {
	Source      RepositoryConfig
	Destination RepositoryConfig
	Server      *Server
}

func PrepareRepositoriesOnAServer

func PrepareRepositoriesOnAServer(
	ctx context.Context,
	server *Server,
	testName string,
	sourceFiles,
	destinationFiles map[string]string) (*Preparation, error)

func (*Preparation) Close

func (p *Preparation) Close(context.Context) error

type RepositoryConfig

type RepositoryConfig struct {
	RepoName string
	HTTP     HTTPConfig
	SSH      SSHConfig
	Session  *Session
}

type SSHConfig

type SSHConfig struct {
	URL                string
	Username           string
	PrivateKey         []byte
	PrivateKeyPassword string
	KnownHosts         []ssh.PublicKey
}

type Server

type Server struct {
	SSHHost  string
	SSHPort  int
	HTTPHost string
	HTTPPort int
	// contains filtered or unexported fields
}

func ListenAndServe

func ListenAndServe(ctx context.Context, giteaImage string) (*Server, error)

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

func (*Server) CreateUser

func (s *Server) CreateUser(ctx context.Context, username, password, email string) error

func (*Server) HTTPAddress

func (s *Server) HTTPAddress() string

func (*Server) NewSession

func (s *Server) NewSession(username, password string) (*Session, error)

func (*Server) SSHAddress

func (s *Server) SSHAddress() string

type Session

type Session struct {
	Username string
	// contains filtered or unexported fields
}

func (*Session) AddPublicKey

func (s *Session) AddPublicKey(ctx context.Context, publicKeyBytes []byte) error

func (*Session) CreateFile

func (s *Session) CreateFile(ctx context.Context, repoName, fileName, contents string) error

func (*Session) CreateRepo

func (s *Session) CreateRepo(ctx context.Context, repoName string) error

func (*Session) CreateTag

func (s *Session) CreateTag(ctx context.Context, repoName, tagName string) error

func (*Session) GetRefs

func (s *Session) GetRefs(ctx context.Context, repoName string) (map[string]string, error)

func (*Session) RemoveAllPublicKeys

func (s *Session) RemoveAllPublicKeys(ctx context.Context) error

Jump to

Keyboard shortcuts

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