Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanhawari committed Mar 7, 2022
1 parent 091b366 commit aa5c4a7
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 180 deletions.
52 changes: 52 additions & 0 deletions lib/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package stew

import (
"os"
"path/filepath"
"testing"
)

func TestGetDefaultStewPath(t *testing.T) {
homeDir, err := os.UserHomeDir()
if err != nil {
t.Errorf("Could not get os.UserHomeDir()")
}
type args struct {
userOS string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "test1",
args: args{
userOS: "darwin",
},
want: filepath.Join(homeDir, ".local", "share", "stew"),
wantErr: false,
},
{
name: "test2",
args: args{
userOS: "windows",
},
want: filepath.Join(homeDir, "AppData", "Local", "stew"),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetDefaultStewPath(tt.args.userOS)
if (err != nil) != tt.wantErr {
t.Errorf("GetDefaultStewPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("GetDefaultStewPath() = %v, want %v", got, tt.want)
}
})
}
}
60 changes: 32 additions & 28 deletions lib/stewfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,34 +293,38 @@ func TestNewLockFileDoesntExist(t *testing.T) {
}
}

// func TestNewSystemInfo(t *testing.T) {
// tests := []struct {
// name string
// }{
// {
// name: "test1",
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// tempDir := t.TempDir()
// testSystemInfo := SystemInfo{
// Os: runtime.GOOS,
// Arch: runtime.GOARCH,
// StewPath: tempDir,
// StewBinPath: filepath.Join(tempDir, "bin"),
// StewPkgPath: filepath.Join(tempDir, "pkg"),
// StewLockFilePath: filepath.Join(tempDir, "Stewfile.lock.json"),
// StewTmpPath: filepath.Join(tempDir, "tmp"),
// }

// got := NewSystemInfo(tempDir)
// if !reflect.DeepEqual(got, testSystemInfo) {
// t.Errorf("NewSystemInfo() = %v, want %v", got, testSystemInfo)
// }
// })
// }
// }
func TestNewSystemInfo(t *testing.T) {
tests := []struct {
name string
}{
{
name: "test1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tempDir := t.TempDir()

testStewConfig := StewConfig{
StewPath: tempDir,
StewBinPath: filepath.Join(tempDir, "bin"),
}

testSystemInfo := SystemInfo{
StewPath: tempDir,
StewBinPath: filepath.Join(tempDir, "bin"),
StewPkgPath: filepath.Join(tempDir, "pkg"),
StewLockFilePath: filepath.Join(tempDir, "Stewfile.lock.json"),
StewTmpPath: filepath.Join(tempDir, "tmp"),
}

got := NewSystemInfo(testStewConfig)
if !reflect.DeepEqual(got, testSystemInfo) {
t.Errorf("NewSystemInfo() = %v, want %v", got, testSystemInfo)
}
})
}
}

func TestDeleteAssetAndBinary(t *testing.T) {
tests := []struct {
Expand Down
Loading

0 comments on commit aa5c4a7

Please sign in to comment.