diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4e66c72..06e4257 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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] diff --git a/README.md b/README.md index cab170d..86fe6ba 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,27 @@ An independent package manager for compiled binaries.
diff --git a/lib/github_test.go b/lib/github_test.go index fe9514d..d85fa6e 100644 --- a/lib/github_test.go +++ b/lib/github_test.go @@ -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) { diff --git a/lib/stewfile_test.go b/lib/stewfile_test.go index e62c92b..3d1c19a 100644 --- a/lib/stewfile_test.go +++ b/lib/stewfile_test.go @@ -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 { @@ -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 diff --git a/lib/util_test.go b/lib/util_test.go index 04a1b9c..ab2ccc5 100644 --- a/lib/util_test.go +++ b/lib/util_test.go @@ -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} @@ -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