deptfile

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package deptfile provides the structure of deptfile and functions to control it.

Index

Constants

This section is empty.

Variables

View Source
var (
	FileName    = "gotool.mod"
	FileSumName = "gotool.sum"
)
View Source
var (
	// ErrNotFound represents deptfile not found.
	ErrNotFound = errors.Errorf("%s not found", FileName)
	// ErrAlreadyExist represents deptfile alredy exist.
	ErrAlreadyExist = errors.New("already exist")
)

Functions

func Create

func Create(ctx context.Context) error

Create creates a new deptfile. If already created, Create returns ErrAlreadyExist.

Types

type File

type File struct {
	Require []*Require
	// contains filtered or unexported fields
}

File represents the root struct of deptfile.

type Require

type Require struct {
	Path      string
	Version   string
	ToolPaths []*Tool
}

Require represents a parsed direct requirement. A Require has least one Tool.

type Tool

type Tool struct {
	Path string
	Name string
}

Tool represents a tool that is belongs to a module. In deptfile representation, a module is represents as a Require. Path is the absolute tool path from the module root. If Path is empty, it means the package of the tool is in the module root. Name is the tool name. If Name is empty, it means Name is the same as filepath.Base(Path).

type Workspace

type Workspace struct {
	// SourcePath is the root path for finding go.mod and go.sum.
	// If SourcePath is empty, SourcePath is the Git project root.
	SourcePath string
	// DoNotCopy doesn't copy gotool.mod and gotool.sum to the workspace.
	DoNotCopy bool
	// DoNotUpdate doesn't update gotool.mod and gotool.sum.
	// It is used for commands which doesn't need to update gotool.mod such like 'dept build'.
	DoNotUpdate bool
}

Workspace is an implementation for Workspacer. The environment is created in a temp dir.

func (*Workspace) Do

func (w *Workspace) Do(f func(projectDir string, gomod *File) error) error

Do copies from the project gotool.mod to a temporary workspace as a go.mod. Then, Do change the current dir to the workspace. After that, Do changes back the current dir and remove the created workspace.

f receives projectDir which is the project root dir.

type Workspacer

type Workspacer interface {
	// Do copies gotool.mod and gotool.sum to the workspace.
	// If gotool.mod is not found, Do returns ErrNotFound.
	Do(f func(projectDir string, gomod *File) error) error
}

Workspacer provides an environment to edit go.mod and go.sum.

type WorkspacerMock

type WorkspacerMock struct {
	// DoFunc mocks the Do method.
	DoFunc func(f func(projectDir string, gomod *File) error) error
	// contains filtered or unexported fields
}

WorkspacerMock is a mock implementation of Workspacer.

    func TestSomethingThatUsesWorkspacer(t *testing.T) {

        // make and configure a mocked Workspacer
        mockedWorkspacer := &WorkspacerMock{
            DoFunc: func(f func(projectDir string, gomod *File) error) error {
	               panic("mock out the Do method")
            },
        }

        // use mockedWorkspacer in code that requires Workspacer
        // and then make assertions.

    }

func (*WorkspacerMock) Do

func (mock *WorkspacerMock) Do(f func(projectDir string, gomod *File) error) error

Do calls DoFunc.

func (*WorkspacerMock) DoCalls

func (mock *WorkspacerMock) DoCalls() []struct {
	F func(projectDir string, gomod *File) error
}

DoCalls gets all the calls that were made to Do. Check the length with:

len(mockedWorkspacer.DoCalls())

Jump to

Keyboard shortcuts

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