Skip to content

Commit

Permalink
test for cURL command
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Apr 26, 2024
1 parent 70b36cf commit 56d8976
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"testing"

scyllaridae "github.com/lehigh-university-libraries/scyllaridae/internal/config"
"github.com/lehigh-university-libraries/scyllaridae/pkg/api"
)

Expand Down Expand Up @@ -58,7 +58,7 @@ cmdByMimeType:
`)
defer os.Unsetenv("SCYLLARIDAE_YML")

config, err = ReadConfig("scyllaridae.yml")
config, err = scyllaridae.ReadConfig("scyllaridae.yml")
if err != nil {
slog.Error("Could not read YML", "err", err)
os.Exit(1)
Expand Down Expand Up @@ -136,8 +136,8 @@ func TestIntegration_GetDestination(t *testing.T) {
defer destinationServer.Close()

// Mock the environment variable for the configuration file path
os.Setenv("SCYLLARIDAE_YML", fmt.Sprintf(`
destinationHttpMethod: "%s"
os.Setenv("SCYLLARIDAE_YML", `
destinationHttpMethod: "`+method+`"
fileHeader: Apix-Ldp-Resource
argHeader: X-Islandora-Args
forwardAuth: false
Expand All @@ -146,15 +146,19 @@ allowedMimeTypes: [
]
cmdByMimeType:
default:
cmd: "cat"
`, method))
cmd: "curl"
args: [
"%s"
]
`)
defer os.Unsetenv("SCYLLARIDAE_YML")

config, err = ReadConfig("scyllaridae.yml")
config, err = scyllaridae.ReadConfig("scyllaridae.yml")
if err != nil {
slog.Error("Could not read YML", "err", err)
os.Exit(1)
}

// Configure and start the main server
setupServer := httptest.NewServer(http.HandlerFunc(MessageHandler))
defer setupServer.Close()
Expand Down Expand Up @@ -203,6 +207,7 @@ cmdByMimeType:
t.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Islandora-Args", destinationServer.URL)

// Capture the response
resp, err := http.DefaultClient.Do(req)
Expand Down

0 comments on commit 56d8976

Please sign in to comment.