archunit

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

Architecture Test Framework For Go Project

GitHub Go Reference Build coverage

What is ArchUnit

ArchUnit is a simple and flexible extensible library for checking the architecture of Golang project. with it, you can make your project's architecture visible, testable and stable by setting a set of predefined architectural rules.

Features

  • This project is inspired by the java version ArchUnit, which has been proven best practice in Java
  • Fully tested and easy to use, it can be used any other popular go test frameworks.
  • NRTW(No Reinventing The Wheel). Keep using builtin golang toolchain at most.

Why architecture test matters?

  1. Maintaining architectural integrity: Architecture tests help ensure that the intended architectural design and principles are followed throughout the development process. They help prevent architectural decay and ensure that the system remains consistent and maintainable over time.
  2. Detecting architectural violations: Architecture tests can identify violations of architectural rules and constraints. They help catch issues such as circular dependencies, improper layering, or violations of design patterns. By detecting these violations early, developers can address them before they become more difficult and costly to fix.
  3. Enforcing best practices: Architecture tests can enforce best practices and coding standards. They can check for adherence to coding conventions, naming conventions, and other guidelines specific to the architectural style or framework being used. This helps maintain a consistent codebase and improves code quality.
  4. Supporting refactoring and evolution: Architecture tests provide confidence when refactoring or making changes to the system. They act as a safety net, ensuring that the intended architectural structure is not compromised during the refactoring process. This allows developers to make changes with more confidence, knowing that they won't introduce unintended side effects.
  5. Facilitating collaboration: Architecture tests serve as a form of documentation that communicates the intended architectural design to the development team. They provide a shared understanding of the system's structure and help facilitate collaboration among team members. Developers can refer to the tests to understand the architectural decisions and constraints in place.

How to Use

  • Import the library
go get github.com/kcmvp/archunit
  • Write a simple test
func TestAllPackages(t *testing.T) {
   pkgs := AllPackages().packages()
   assert.Equal(t, 12, len(pkgs))
   err := AllPackages().NameShouldBeSameAsFolder()
   assert.NotNil(t, err)
}

Principles apply to all checks

  • All the checks return an error when it fails, nil error stands for success
  • The error contains detail information about the failure
  • Two steps to define a check
    • Define the criteria of the objects to be checking
    • Apply rules

All Checks

Package checks

Roadmap

  • Package checks
    • Dependency checks
    • Naming checks
  • Project Layout checks
  • Method checks

Documentation

Overview

nolint

nolint

nolint

nolint

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstantsShouldBeDefinedInOneFileByPackage added in v0.1.2

func ConstantsShouldBeDefinedInOneFileByPackage() error

func HavePrefix added in v0.1.2

func HavePrefix(name, prefix string) bool

func HaveSuffix added in v0.1.2

func HaveSuffix(name, suffix string) bool

func LowerCase added in v0.1.2

func LowerCase(name, _ string) bool

func MethodsOfTypeShouldBeDefinedInSameFile added in v0.1.2

func MethodsOfTypeShouldBeDefinedInSameFile() error

func PackageNameShouldBe added in v0.1.2

func PackageNameShouldBe(pattern NamePattern, args ...string) error

func PackageNameShouldBeSameAsFolderName added in v0.1.2

func PackageNameShouldBeSameAsFolderName() error

func SourceNameShouldBe added in v0.1.2

func SourceNameShouldBe(pattern NamePattern, args ...string) error

func UpperCase added in v0.1.2

func UpperCase(name, _ string) bool

Types

type File added in v0.1.2

type File lo.Tuple2[string, []string]

type Files

type Files []File

func (Files) NameShould added in v0.1.2

func (f Files) NameShould(pattern NamePattern) error

func (Files) ShouldNotRefer added in v0.1.2

func (f Files) ShouldNotRefer(paths ...string) error

type Function added in v0.1.2

type Function lo.Tuple2[string, []string]

func (Function) Exclude added in v0.1.2

func (functions Function) Exclude(names ...string) Function

func (Function) InPackage added in v0.1.2

func (functions Function) InPackage(paths ...string) Function

func (Function) NameShould added in v0.1.2

func (functions Function) NameShould(pattern NamePattern) error

func (Function) OfType added in v0.1.2

func (functions Function) OfType(types ...string) Function

func (Function) ShouldBePrivate added in v0.1.2

func (functions Function) ShouldBePrivate() error

func (Function) ShouldBePublic added in v0.1.2

func (functions Function) ShouldBePublic() error

func (Function) WithParameter added in v0.1.2

func (functions Function) WithParameter() Function

func (Function) WithReturn added in v0.1.2

func (functions Function) WithReturn() Function

type Layer added in v0.1.2

type Layer lo.Tuple2[string, []*internal.Package]

func Packages

func Packages(layerName string, paths []string) Layer

func (Layer) DepthShouldLessThan added in v0.1.2

func (layer Layer) DepthShouldLessThan(depth int) error

func (Layer) Exclude added in v0.1.2

func (layer Layer) Exclude(paths ...string) Layer

func (Layer) Files added in v0.1.2

func (layer Layer) Files() Files

func (Layer) FilesInPackages added in v0.1.2

func (layer Layer) FilesInPackages(paths ...string) Files

func (Layer) Imports added in v0.1.2

func (layer Layer) Imports() []string

func (Layer) Package added in v0.1.2

func (layer Layer) Package(path string) Package

func (Layer) Packages added in v0.1.2

func (layer Layer) Packages() []string

func (Layer) ShouldBeOnlyReferredByLayers added in v0.1.2

func (layer Layer) ShouldBeOnlyReferredByLayers(layers ...Layer) error

func (Layer) ShouldBeOnlyReferredByPackages added in v0.1.2

func (layer Layer) ShouldBeOnlyReferredByPackages(paths ...string) error

func (Layer) ShouldNotReferLayers added in v0.1.2

func (layer Layer) ShouldNotReferLayers(layers ...Layer) error

func (Layer) ShouldNotReferPackages added in v0.1.2

func (layer Layer) ShouldNotReferPackages(paths ...string) error

func (Layer) ShouldOnlyReferLayers added in v0.1.2

func (layer Layer) ShouldOnlyReferLayers(layers ...Layer) error

func (Layer) ShouldOnlyReferPackages added in v0.1.2

func (layer Layer) ShouldOnlyReferPackages(paths ...string) error

func (Layer) Sub added in v0.1.2

func (layer Layer) Sub(name string, paths ...string) Layer

func (Layer) Types added in v0.1.2

func (layer Layer) Types() Types

type NamePattern added in v0.1.2

type NamePattern func(name, arg string) bool

type Package added in v0.1.2

type Package lo.Tuple2[string, string]

func (Package) ShouldBeOnlyReferredBy added in v0.1.2

func (pkg Package) ShouldBeOnlyReferredBy(path ...string) error

func (Package) ShouldNotRefer added in v0.1.2

func (pkg Package) ShouldNotRefer(path ...string) error

type Type added in v0.1.2

type Type struct {
	// contains filtered or unexported fields
}

func TypeImplement added in v0.1.2

func TypeImplement(interName string) []Type

func (Type) Exclude added in v0.1.2

func (types Type) Exclude(names ...string) Types

type Types added in v0.1.2

type Types []Type

func TypeEmbeddedWith added in v0.1.2

func TypeEmbeddedWith(embeds ...string) Types

func (Types) EmbeddedWith added in v0.1.2

func (types Types) EmbeddedWith(embeds ...string) Types

func (Types) Functions added in v0.1.2

func (types Types) Functions() []Function

func (Types) Implement added in v0.1.2

func (types Types) Implement(inters ...string) Types

func (Types) InPackage added in v0.1.2

func (types Types) InPackage(paths ...string) Types

func (Types) NameShould added in v0.1.2

func (types Types) NameShould(pattern NamePattern) error

func (Types) ShouldBeInPackages added in v0.1.2

func (types Types) ShouldBeInPackages(pkgs ...string) error

func (Types) ShouldBePrivate added in v0.1.2

func (types Types) ShouldBePrivate() error

func (Types) ShouldBePublic added in v0.1.2

func (functions Types) ShouldBePublic() error

Jump to

Keyboard shortcuts

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