feat: add first go tests
This commit is contained in:
parent
43364d735b
commit
f4773a9521
2 changed files with 46 additions and 1 deletions
|
|
@ -9,10 +9,18 @@ linter:
|
||||||
script:
|
script:
|
||||||
- "golangci-lint run"
|
- "golangci-lint run"
|
||||||
|
|
||||||
|
testing:
|
||||||
|
stage: "testing"
|
||||||
|
needs:
|
||||||
|
- "linter"
|
||||||
|
image: "cr.simoncor.net/siempie/go-build:latest"
|
||||||
|
script:
|
||||||
|
- "go test cmd/gogitlabber/*"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
stage: "build"
|
stage: "build"
|
||||||
needs:
|
needs:
|
||||||
- "linter"
|
- "testing"
|
||||||
image: "cr.simoncor.net/siempie/go-build:latest"
|
image: "cr.simoncor.net/siempie/go-build:latest"
|
||||||
script:
|
script:
|
||||||
- "GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o gogitlabber cmd/gogitlabber/*"
|
- "GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o gogitlabber cmd/gogitlabber/*"
|
||||||
|
|
|
||||||
37
cmd/gogitlabber/prerequisites_test.go
Normal file
37
cmd/gogitlabber/prerequisites_test.go
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// new type for the lookup function
|
||||||
|
type lookPathFunc func(file string) (string, error)
|
||||||
|
|
||||||
|
// modified function to accept a lookup function
|
||||||
|
func verifyGitAvailableWithLookup(lookPath lookPathFunc) error {
|
||||||
|
_, err := lookPath("git")
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("could not find git in path")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVerifyGitAvailable(t *testing.T) {
|
||||||
|
|
||||||
|
// test case 1: git is available
|
||||||
|
err := verifyGitAvailableWithLookup(func(file string) (string, error) {
|
||||||
|
return "/usr/bin/git", nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Expected no error when git is available, got: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// test case 2: git is not available
|
||||||
|
err = verifyGitAvailableWithLookup(func(file string) (string, error) {
|
||||||
|
return "", errors.New("git not found")
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected error when git is not available, got nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue