Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Dec 30, 2024
1 parent 99461db commit 164411e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:

- name: Make Test
id: unit-test
run: go test ./... -count=1
run: go test ./... -v -count=1
16 changes: 14 additions & 2 deletions thorbuilder/thorbuilder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package thorbuilder

import (
"bytes"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -56,6 +57,10 @@ func (b *Builder) Download() error {

// Build runs the make command in the downloadPath and returns the path to the thor binary.
func (b *Builder) Build() (string, error) {
if _, err := os.Stat(b.downloadPath); os.IsNotExist(err) {
return "", fmt.Errorf("download directory does not exist: %s", b.downloadPath)
}

if b.reusable {
// Check if the binary exists and if it does return the path
thorBinaryPath := filepath.Join(b.downloadPath, "bin", "thor")
Expand All @@ -67,10 +72,17 @@ func (b *Builder) Build() (string, error) {

makeCmd := exec.Command("make")
makeCmd.Dir = b.downloadPath
makeCmd.Stdout = os.Stdout
makeCmd.Stderr = os.Stderr
// Capture output
var stdout, stderr bytes.Buffer
makeCmd.Stdout = &stdout
makeCmd.Stderr = &stderr

if err := makeCmd.Run(); err != nil {
slog.Error("Make command failed",
"stdout", stdout.String(),
"stderr", stderr.String(),
"error", err,
)
return "", fmt.Errorf("failed to build project: %w", err)
}

Expand Down
16 changes: 8 additions & 8 deletions thorbuilder/thorbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func TestBuilder(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, filepath.Join(builder.downloadPath, "bin", "thor"), thorBinaryPath)

// Second download should skip cloning
err = builder.Download()
require.NoError(t, err)

// Second build should skip building if the binary exists
thorBinaryPath, err = builder.Build()
require.NoError(t, err)
assert.Equal(t, filepath.Join(builder.downloadPath, "bin", "thor"), thorBinaryPath)
//// Second download should skip cloning
//err = builder.Download()
//require.NoError(t, err)
//
//// Second build should skip building if the binary exists
//thorBinaryPath, err = builder.Build()
//require.NoError(t, err)
//assert.Equal(t, filepath.Join(builder.downloadPath, "bin", "thor"), thorBinaryPath)
})

t.Run("Test Build Non-Reusable", func(t *testing.T) {
Expand Down

0 comments on commit 164411e

Please sign in to comment.