cmd/osbuild-worker-executor: import verbatim from mvo5/oaas
This commit imports the repository https://github.com/mvo5/oaas without keeping the history. The history is largely unimportant and can be looked up in https://github.com/mvo5/oaas/commits/main if needed.
This commit is contained in:
parent
fa416e4545
commit
372d9f07dd
12 changed files with 1024 additions and 0 deletions
62
cmd/osbuild-worker-executor/handler_result_test.go
Normal file
62
cmd/osbuild-worker-executor/handler_result_test.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package main_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestResultTooEarly(t *testing.T) {
|
||||
baseURL, _, _ := runTestServer(t)
|
||||
endpoint := baseURL + "api/v1/result"
|
||||
|
||||
rsp, err := http.Get(endpoint)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, rsp.StatusCode, http.StatusTooEarly)
|
||||
}
|
||||
|
||||
func TestResultBad(t *testing.T) {
|
||||
baseURL, buildBaseDir, _ := runTestServer(t)
|
||||
endpoint := baseURL + "api/v1/result/disk.img"
|
||||
|
||||
// simulate build failure
|
||||
// todo: make a nice helper method
|
||||
err := os.MkdirAll(filepath.Join(buildBaseDir, "build"), 0755)
|
||||
assert.NoError(t, err)
|
||||
err = ioutil.WriteFile(filepath.Join(buildBaseDir, "result.bad"), nil, 0644)
|
||||
assert.NoError(t, err)
|
||||
err = ioutil.WriteFile(filepath.Join(buildBaseDir, "build/build.log"), []byte("failure log"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
rsp, err := http.Get(endpoint)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusBadRequest, rsp.StatusCode)
|
||||
body, err := ioutil.ReadAll(rsp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "build failed\nfailure log", string(body))
|
||||
}
|
||||
|
||||
func TestResultGood(t *testing.T) {
|
||||
baseURL, buildBaseDir, _ := runTestServer(t)
|
||||
endpoint := baseURL + "api/v1/result/disk.img"
|
||||
|
||||
// simulate build failure
|
||||
// todo: make a nice helper method
|
||||
err := os.MkdirAll(filepath.Join(buildBaseDir, "build/output"), 0755)
|
||||
assert.NoError(t, err)
|
||||
err = ioutil.WriteFile(filepath.Join(buildBaseDir, "result.good"), nil, 0644)
|
||||
assert.NoError(t, err)
|
||||
err = ioutil.WriteFile(filepath.Join(buildBaseDir, "build/output/disk.img"), []byte("fake-build-result"), 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
rsp, err := http.Get(endpoint)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, rsp.StatusCode)
|
||||
body, err := ioutil.ReadAll(rsp.Body)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "fake-build-result", string(body))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue