Skip to content

Commit

Permalink
Add very first unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Mar 8, 2024
1 parent 6d01d86 commit 54136ea
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/download/download_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package download

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

func TestGetDownloadLocation(t *testing.T) {
tempDir := t.TempDir()
os.Setenv("HOME", tempDir)

Check failure on line 11 in pkg/download/download_test.go

View workflow job for this annotation

GitHub Actions / build

os.Setenv() can be replaced by `t.Setenv()` in TestGetDownloadLocation (tenv)
downloadLocation := GetDownloadLocation()

expectedLocation := filepath.Join(tempDir, ".tfversion", "versions")
if downloadLocation != expectedLocation {
t.Errorf("Expected download location %s, but got %s", expectedLocation, downloadLocation)
}

_, err := os.Stat(downloadLocation)
if os.IsNotExist(err) {
t.Errorf("Download location directory does not exist: %s", downloadLocation)
}
}

0 comments on commit 54136ea

Please sign in to comment.