Compare commits

..

No commits in common. "feature-1" and "main" have entirely different histories.

6 changed files with 25 additions and 60 deletions

View File

@ -1,46 +1,17 @@
kind: pipeline kind: pipeline
type: docker type: docker
name: go-lib/util name: go-lib/util
environment:
VERSION: development
workspace:
base: /go
path: /src/scm.yoorie.de/go-lib/util
steps: steps:
- name: prepare - name: build
image: golang
commands:
- go get -v ./...
- go install gotest.tools/gotestsum@v1.13.0
- go install golang.org/x/vuln/cmd/govulncheck@latest
- name: test
image: golang image: golang
commands: commands:
- mkdir -p .build - mkdir -p .build
- go install gotest.tools/gotestsum@v1.9.0
- go get ./...
- gotestsum --format testname --junitfile .build/unittests.xml -- -coverprofile=.build/coverage.txt ./... - gotestsum --format testname --junitfile .build/unittests.xml -- -coverprofile=.build/coverage.txt ./...
depends_on: - go install golang.org/x/vuln/cmd/govulncheck@latest
- prepare - govulncheck -v ./...
- name: vulncheck
image: golang
commands:
- govulncheck ./...
- ls -la /go/
depends_on:
- prepare
- name: publish
image: golang
commands:
- echo "Publishing not implemented yet"
when:
branch:
- main
event:
- custom
trigger: trigger:
event: event:

1
.gitignore vendored
View File

@ -1 +0,0 @@
.build/

13
go.mod
View File

@ -1,15 +1,8 @@
module scm.yoorie.de/go-lib/util module scm.yoorie.de/go-lib/util
go 1.24.0 go 1.16
require ( require (
github.com/stretchr/testify v1.11.1 github.com/stretchr/testify v1.8.2
golang.org/x/sys v0.36.0 golang.org/x/sys v0.6.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

23
go.sum
View File

@ -1,18 +1,19 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -12,7 +12,7 @@ import (
// A.K.A root, Administrator etc // A.K.A root, Administrator etc
func IsSuperUser() bool { func IsSuperUser() bool {
cuser, err := user.Current() cuser, err := user.Current()
return err == nil && cuser.Uid == "0" return err == nil && "0" == cuser.Uid
} }
// GetGlobalConfigurationDirectory returns OS specific location for putting // GetGlobalConfigurationDirectory returns OS specific location for putting

View File

@ -1,6 +1,7 @@
package util package util
import ( import (
"fmt"
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@ -66,7 +67,7 @@ func TestIsSuperUser(t *testing.T) {
func TestGlobalConfigurationDirectoryWindows(t *testing.T) { func TestGlobalConfigurationDirectoryWindows(t *testing.T) {
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
t.Skipf("Skipping on OS %s", runtime.GOOS) t.Skip(fmt.Sprintf("Skipping on OS %s", runtime.GOOS))
} }
appFolder := GetGlobalConfigurationDirectory("myapp") appFolder := GetGlobalConfigurationDirectory("myapp")
assert.Equal(t, filepath.Join(os.Getenv("APPDATA"), "myapp"), appFolder) assert.Equal(t, filepath.Join(os.Getenv("APPDATA"), "myapp"), appFolder)
@ -74,7 +75,7 @@ func TestGlobalConfigurationDirectoryWindows(t *testing.T) {
func TestGlobalConfigurationDirectoryLinux(t *testing.T) { func TestGlobalConfigurationDirectoryLinux(t *testing.T) {
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
t.Skipf("Skipping on OS %s", runtime.GOOS) t.Skip(fmt.Sprintf("Skipping on OS %s", runtime.GOOS))
} }
appFolder := GetGlobalConfigurationDirectory("myapp") appFolder := GetGlobalConfigurationDirectory("myapp")
assert.Equal(t, "/etc/myapp", appFolder) assert.Equal(t, "/etc/myapp", appFolder)
@ -82,7 +83,7 @@ func TestGlobalConfigurationDirectoryLinux(t *testing.T) {
func TestGlobalConfigurationDirectoryMacOS(t *testing.T) { func TestGlobalConfigurationDirectoryMacOS(t *testing.T) {
if runtime.GOOS != "darwin" { if runtime.GOOS != "darwin" {
t.Skipf("Skipping on OS %s", runtime.GOOS) t.Skip(fmt.Sprintf("Skipping on OS %s", runtime.GOOS))
} }
appFolder := GetGlobalConfigurationDirectory("myapp") appFolder := GetGlobalConfigurationDirectory("myapp")
assert.Equal(t, "/etc/myapp", appFolder) assert.Equal(t, "/etc/myapp", appFolder)