#166 Adjust outdated make command pattern
as with #147 a new unset command part is introduced. Also add a regression e2e test that would have caught this issue.
This commit is contained in:
@@ -22,7 +22,7 @@ class InvalidMakefileException extends Exception {}
|
|||||||
class SimpleMakefile {
|
class SimpleMakefile {
|
||||||
|
|
||||||
// This pattern validates if a command is a make command.
|
// This pattern validates if a command is a make command.
|
||||||
private static final Pattern isMakeCommand = Pattern.compile("^make(?:\\s+(?<startRule>\\w*))?(?<assignments>(?:.*?=.*?)+)?$");
|
private static final Pattern isMakeCommand = Pattern.compile("^(?:.* && )?make(?:\\s+(?<startRule>\\w*))?(?<assignments>(?:.*?=.*?)+)?(?: && .*)?$");
|
||||||
|
|
||||||
// This pattern identifies the rules in a makefile.
|
// This pattern identifies the rules in a makefile.
|
||||||
private static final Pattern makeRules = Pattern.compile("(?<name>.*):\\r?\\n(?<commands>(?:\\t.+\\r?\\n?)*)");
|
private static final Pattern makeRules = Pattern.compile("(?<name>.*):\\r?\\n(?<commands>(?:\\t.+\\r?\\n?)*)");
|
||||||
|
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/openHPI/poseidon/pkg/dto"
|
"github.com/openHPI/poseidon/pkg/dto"
|
||||||
"github.com/openHPI/poseidon/tests"
|
"github.com/openHPI/poseidon/tests"
|
||||||
"github.com/openHPI/poseidon/tests/helpers"
|
"github.com/openHPI/poseidon/tests/helpers"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -78,6 +77,18 @@ func ProvideRunner(request *dto.RunnerRequest) (string, error) {
|
|||||||
return runnerResponse.ID, nil
|
return runnerResponse.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CopyFiles sends the dto.UpdateFileSystemRequest to Poseidon.
|
||||||
|
// It needs a running Poseidon instance to work.
|
||||||
|
func CopyFiles(runnerID string, request *dto.UpdateFileSystemRequest) (*http.Response, error) {
|
||||||
|
data, err := json.Marshal(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
return helpers.HTTPPatch(helpers.BuildURL(api.BasePath, api.RunnersPath, runnerID, api.UpdateFileSystemPath),
|
||||||
|
"application/json", r)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *E2ETestSuite) TestDeleteRunnerRoute() {
|
func (s *E2ETestSuite) TestDeleteRunnerRoute() {
|
||||||
for _, environmentID := range environmentIDs {
|
for _, environmentID := range environmentIDs {
|
||||||
s.Run(environmentID.ToString(), func() {
|
s.Run(environmentID.ToString(), func() {
|
||||||
@@ -111,17 +122,13 @@ func (s *E2ETestSuite) TestCopyFilesRoute() {
|
|||||||
s.Run(environmentID.ToString(), func() {
|
s.Run(environmentID.ToString(), func() {
|
||||||
runnerID, err := ProvideRunner(&dto.RunnerRequest{ExecutionEnvironmentID: int(environmentID)})
|
runnerID, err := ProvideRunner(&dto.RunnerRequest{ExecutionEnvironmentID: int(environmentID)})
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
copyFilesRequestByteString, err := json.Marshal(&dto.UpdateFileSystemRequest{
|
|
||||||
|
request := &dto.UpdateFileSystemRequest{
|
||||||
Copy: []dto.File{{Path: tests.DefaultFileName, Content: []byte(tests.DefaultFileContent)}},
|
Copy: []dto.File{{Path: tests.DefaultFileName, Content: []byte(tests.DefaultFileContent)}},
|
||||||
})
|
|
||||||
s.Require().NoError(err)
|
|
||||||
sendCopyRequest := func(reader io.Reader) (*http.Response, error) {
|
|
||||||
return helpers.HTTPPatch(helpers.BuildURL(api.BasePath, api.RunnersPath, runnerID, api.UpdateFileSystemPath),
|
|
||||||
"application/json", reader)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Run("File copy with valid payload succeeds", func() {
|
s.Run("File copy with valid payload succeeds", func() {
|
||||||
resp, err := sendCopyRequest(bytes.NewReader(copyFilesRequestByteString))
|
resp, err := CopyFiles(runnerID, request)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Equal(http.StatusNoContent, resp.StatusCode)
|
s.Equal(http.StatusNoContent, resp.StatusCode)
|
||||||
|
|
||||||
@@ -135,15 +142,15 @@ func (s *E2ETestSuite) TestCopyFilesRoute() {
|
|||||||
relativeFileContent := "Relative file content"
|
relativeFileContent := "Relative file content"
|
||||||
absoluteFilePath := "/tmp/absolute/file/path.txt"
|
absoluteFilePath := "/tmp/absolute/file/path.txt"
|
||||||
absoluteFileContent := "Absolute file content"
|
absoluteFileContent := "Absolute file content"
|
||||||
testFilePathsCopyRequestString, err := json.Marshal(&dto.UpdateFileSystemRequest{
|
request = &dto.UpdateFileSystemRequest{
|
||||||
Copy: []dto.File{
|
Copy: []dto.File{
|
||||||
{Path: dto.FilePath(relativeFilePath), Content: []byte(relativeFileContent)},
|
{Path: dto.FilePath(relativeFilePath), Content: []byte(relativeFileContent)},
|
||||||
{Path: dto.FilePath(absoluteFilePath), Content: []byte(absoluteFileContent)},
|
{Path: dto.FilePath(absoluteFilePath), Content: []byte(absoluteFileContent)},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
resp, err := sendCopyRequest(bytes.NewReader(testFilePathsCopyRequestString))
|
resp, err := CopyFiles(runnerID, request)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Equal(http.StatusNoContent, resp.StatusCode)
|
s.Equal(http.StatusNoContent, resp.StatusCode)
|
||||||
|
|
||||||
@@ -158,12 +165,12 @@ func (s *E2ETestSuite) TestCopyFilesRoute() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
s.Run("File deletion request deletes file on runner", func() {
|
s.Run("File deletion request deletes file on runner", func() {
|
||||||
copyFilesRequestByteString, err := json.Marshal(&dto.UpdateFileSystemRequest{
|
request = &dto.UpdateFileSystemRequest{
|
||||||
Delete: []dto.FilePath{tests.DefaultFileName},
|
Delete: []dto.FilePath{tests.DefaultFileName},
|
||||||
})
|
}
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
resp, err := sendCopyRequest(bytes.NewReader(copyFilesRequestByteString))
|
resp, err := CopyFiles(runnerID, request)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Equal(http.StatusNoContent, resp.StatusCode)
|
s.Equal(http.StatusNoContent, resp.StatusCode)
|
||||||
|
|
||||||
@@ -175,13 +182,13 @@ func (s *E2ETestSuite) TestCopyFilesRoute() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
s.Run("File copy happens after file deletion", func() {
|
s.Run("File copy happens after file deletion", func() {
|
||||||
copyFilesRequestByteString, err := json.Marshal(&dto.UpdateFileSystemRequest{
|
request = &dto.UpdateFileSystemRequest{
|
||||||
Delete: []dto.FilePath{tests.DefaultFileName},
|
Delete: []dto.FilePath{tests.DefaultFileName},
|
||||||
Copy: []dto.File{{Path: tests.DefaultFileName, Content: []byte(tests.DefaultFileContent)}},
|
Copy: []dto.File{{Path: tests.DefaultFileName, Content: []byte(tests.DefaultFileContent)}},
|
||||||
})
|
}
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
resp, err := sendCopyRequest(bytes.NewReader(copyFilesRequestByteString))
|
resp, err := CopyFiles(runnerID, request)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Equal(http.StatusNoContent, resp.StatusCode)
|
s.Equal(http.StatusNoContent, resp.StatusCode)
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
@@ -199,9 +206,7 @@ func (s *E2ETestSuite) TestCopyFilesRoute() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
s.Run("Copying to non-existing runner returns NotFound", func() {
|
s.Run("Copying to non-existing runner returns NotFound", func() {
|
||||||
resp, err := helpers.HTTPPatch(
|
resp, err := CopyFiles(tests.NonExistingStringID, request)
|
||||||
helpers.BuildURL(api.BasePath, api.RunnersPath, tests.NonExistingStringID, api.UpdateFileSystemPath),
|
|
||||||
"application/json", bytes.NewReader(copyFilesRequestByteString))
|
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
s.Equal(http.StatusNotFound, resp.StatusCode)
|
s.Equal(http.StatusNotFound, resp.StatusCode)
|
||||||
})
|
})
|
||||||
|
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/openHPI/poseidon/tests/helpers"
|
"github.com/openHPI/poseidon/tests/helpers"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -124,6 +125,40 @@ func (s *E2ETestSuite) TestCommandHead() {
|
|||||||
s.Contains(stdout, fmt.Sprintf("%s\r\n%s\r\n", hello, hello))
|
s.Contains(stdout, fmt.Sprintf("%s\r\n%s\r\n", hello, hello))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *E2ETestSuite) TestCommandMake() {
|
||||||
|
for _, environmentID := range environmentIDs {
|
||||||
|
s.Run(environmentID.ToString(), func() {
|
||||||
|
runnerID, err := ProvideRunner(&dto.RunnerRequest{ExecutionEnvironmentID: int(environmentID)})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
expectedOutput := "MeinText"
|
||||||
|
resp, err := CopyFiles(runnerID, &dto.UpdateFileSystemRequest{
|
||||||
|
Copy: []dto.File{
|
||||||
|
{Path: "Makefile", Content: []byte(
|
||||||
|
"run:\n\t@echo " + expectedOutput + "\n\n" +
|
||||||
|
"test:\n\t@echo Hi\n"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Equal(http.StatusNoContent, resp.StatusCode)
|
||||||
|
|
||||||
|
webSocketURL, err := ProvideWebSocketURL(&s.Suite, runnerID, &dto.ExecutionRequest{Command: "make run"})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
connection, err := ConnectToWebSocket(webSocketURL)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
messages, err := helpers.ReceiveAllWebSocketMessages(connection)
|
||||||
|
s.Require().Error(err)
|
||||||
|
s.Equal(err, &websocket.CloseError{Code: websocket.CloseNormalClosure})
|
||||||
|
stdout, _, _ := helpers.WebSocketOutputMessages(messages)
|
||||||
|
|
||||||
|
stdout = regexp.MustCompile(`\r?\n$`).ReplaceAllString(stdout, "")
|
||||||
|
s.Equal(expectedOutput, stdout)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *E2ETestSuite) TestCommandReturnsAfterTimeout() {
|
func (s *E2ETestSuite) TestCommandReturnsAfterTimeout() {
|
||||||
for _, environmentID := range environmentIDs {
|
for _, environmentID := range environmentIDs {
|
||||||
s.Run(environmentID.ToString(), func() {
|
s.Run(environmentID.ToString(), func() {
|
||||||
|
Reference in New Issue
Block a user