Skip to content

Commit

Permalink
add coveralls coverage service and add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanhawari committed Feb 15, 2022
1 parent 9cecf5e commit cf68ef5
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 8 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ jobs:
go-version: ${{ matrix.go-version }}

- name: Test and calculate coverage
run: go test -v ./... --coverprofile coverage.out
run: go test -v ./lib --coverprofile coverage.out
- name: Read the coverage
run: go tool cover --func coverage.out
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=coverage.out -service=github

goreleaser:
needs: [test]
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,27 @@
An independent package manager for compiled binaries.
</p>
<p align="center">
<img src="https://github.com/marwanhawari/stew/actions/workflows/test.yml/badge.svg" alt="build status"/>
<img src="https://goreportcard.com/badge/github.com/marwanhawari/stew" alt="go report card"/>
<img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg" alt="code of conduct"/>
<img src="https://img.shields.io/github/license/marwanhawari/stew?color=blue" alt="license"/>

<a href="https://github.com/marwanhawari/stew/actions/">
<img src="https://github.com/marwanhawari/stew/actions/workflows/test.yml/badge.svg" alt="build status"/>
</a>

<a href="https://goreportcard.com/report/github.com/marwanhawari/stew">
<img src="https://goreportcard.com/badge/github.com/marwanhawari/stew" alt="go report card"/>
</a>

<a href='https://coveralls.io/github/marwanhawari/stew?branch=main'>
<img src='https://coveralls.io/repos/github/marwanhawari/stew/badge.svg?branch=main' alt='Coverage Status'/>
</a>

<a href="https://pkg.go.dev/github.com/marwanhawari/stew">
<img src="https://pkg.go.dev/badge/github.com/marwanhawari/stew.svg" alt="pkg.go.dev reference"/>
</a>

<a href="https://github.com/marwanhawari/stew/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/marwanhawari/stew?color=blue" alt="license"/>
</a>

</p>


Expand Down
20 changes: 20 additions & 0 deletions lib/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,26 @@ func TestDetectAsset(t *testing.T) {
want: "",
wantErr: true,
},
{
name: "test6",
args: args{
userOS: "windows",
userArch: "386",
releaseAssets: append(testReleaseAssets, "ppath-v0.0.1-windows-386.tar.gz"),
},
want: "ppath-v0.0.1-windows-386.tar.gz",
wantErr: false,
},
{
name: "test7",
args: args{
userOS: "windows",
userArch: "unexpectedArch",
releaseAssets: append(testReleaseAssets, "ppath-v0.0.1-windows-unexpectedArch.tar.gz"),
},
want: "ppath-v0.0.1-windows-unexpectedArch.tar.gz",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
54 changes: 52 additions & 2 deletions lib/stewfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,23 @@ func TestRemovePackage(t *testing.T) {
want: []PackageData{},
wantErr: true,
},
{
name: "test5",
args: args{
index: 0,
},
want: []PackageData{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
testLockfilePackages := make([]PackageData, len(testLockfile.Packages))
copy(testLockfilePackages, testLockfile.Packages)
var testLockfilePackages []PackageData

if tt.name != "test5" {
testLockfilePackages = make([]PackageData, len(testLockfile.Packages))
copy(testLockfilePackages, testLockfile.Packages)
}

got, err := RemovePackage(testLockfilePackages, tt.args.index)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -244,6 +256,44 @@ func TestNewLockFile(t *testing.T) {
}
}

func TestNewLockFileDoesntExist(t *testing.T) {
type args struct {
userOS string
userArch string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "test1",
args: args{
userOS: testLockfile.Os,
userArch: testLockfile.Arch,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

tempDir := t.TempDir()
lockFilePath := path.Join(tempDir, "Stewfile.lock.json")

got, err := NewLockFile(lockFilePath, tt.args.userOS, tt.args.userArch)
if (err != nil) != tt.wantErr {
t.Errorf("NewLockFile() error = %v, wantErr %v", err, tt.wantErr)
return
}
want := LockFile{Os: tt.args.userOS, Arch: tt.args.userArch, Packages: []PackageData{}}
if !reflect.DeepEqual(got, want) {
t.Errorf("NewLockFile() = %v, want %v", got, want)
}
})
}
}

func TestNewSystemInfo(t *testing.T) {
tests := []struct {
name string
Expand Down
48 changes: 47 additions & 1 deletion lib/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func Test_getBinary(t *testing.T) {
testBinaryFilePath := path.Join(tempDir, tt.binaryName)
ioutil.WriteFile(testBinaryFilePath, []byte("An executable file"), 0755)
testNonBinaryFilePath := path.Join(tempDir, "testNonBinary")
ioutil.WriteFile(testNonBinaryFilePath, []byte("An executable file"), 0644)
ioutil.WriteFile(testNonBinaryFilePath, []byte("Not an executable file"), 0644)

testFilePaths := []string{testBinaryFilePath, testNonBinaryFilePath}

Expand All @@ -362,6 +362,52 @@ func Test_getBinary(t *testing.T) {
}
}

func Test_getBinaryError(t *testing.T) {
type args struct {
repo string
}
tests := []struct {
name string
args args
binaryName string
wantErr bool
}{
{
name: "test1",
args: args{
repo: "testBinary",
},
binaryName: "testBinary",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tempDir := t.TempDir()

testNonBinaryFilePath := path.Join(tempDir, "testNonBinary")
ioutil.WriteFile(testNonBinaryFilePath, []byte("Not an executable file"), 0644)

testFilePaths := []string{testNonBinaryFilePath}

wantBinaryFile := ""
wantBinaryName := ""

got, got1, err := getBinary(testFilePaths, tt.args.repo)
if (err != nil) != tt.wantErr {
t.Errorf("getBinary() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != wantBinaryFile {
t.Errorf("getBinary() got = %v, want %v", got, wantBinaryFile)
}
if got1 != wantBinaryName {
t.Errorf("getBinary() got1 = %v, want %v", got1, wantBinaryName)
}
})
}
}

func TestValidateCLIInput(t *testing.T) {
type args struct {
cliInput string
Expand Down

0 comments on commit cf68ef5

Please sign in to comment.