68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// 1703b: the fetch step asks git, through the SDK's FetchCommit, for the ssh remote of the forge as the account, makes
|
|
// the workspace's tree in the work directory and answers its id and the commit; it downloads nothing else.
|
|
func TestFetchAsksGitForTheSshRemoteIntoAWorkspace(t *testing.T) {
|
|
f := newFake(t)
|
|
states := newStates()
|
|
m := moduleWith(t, f, states)
|
|
ans, err := tool(t, m, FetchTool)(map[string]any{"repository": "novox/mesh-catalog", "commit": commitSHA, "ref": "refs/pull/7/head"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if a := ans.(map[string]any); a["state"] != delivery.StepRunning || a["step"] == "" {
|
|
t.Errorf("the call answered %v, want a running step", a)
|
|
}
|
|
st := states.waitEnd(t)
|
|
if st.State != delivery.StepPassed {
|
|
t.Fatalf("step = %+v", st)
|
|
}
|
|
var res FetchResult
|
|
if err := json.Unmarshal(st.Result, &res); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if res.Commit != commitSHA || res.Workspace == "" || res.Merge != "" {
|
|
t.Errorf("result = %+v", res)
|
|
}
|
|
if info, err := os.Stat(filepath.Join(m.Work, res.Workspace, "tree")); err != nil || !info.IsDir() {
|
|
t.Errorf("no tree in the workspace: %v", err)
|
|
}
|
|
joined := strings.Join(f.lines(), "\n")
|
|
if !strings.Contains(joined, "ssh://mesh-forge/novox/mesh-catalog.git") || !strings.Contains(joined, commitSHA) {
|
|
t.Errorf("git was not asked for the forge's ssh remote and the commit:\n%s", joined)
|
|
}
|
|
for _, l := range f.lines() {
|
|
if strings.Contains(l, "buildah bud") || strings.HasPrefix(l, "go ") {
|
|
t.Errorf("a fetch ran %q", l)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFetchRefusesWhatIsNotARepositoryOrACommit(t *testing.T) {
|
|
for name, args := range map[string]map[string]any{
|
|
"repository": {"repository": "../etc", "commit": commitSHA},
|
|
"commit": {"repository": "novox/mesh-catalog", "commit": "main"},
|
|
"base": {"repository": "novox/mesh-catalog", "commit": commitSHA, "base": "trunk"},
|
|
} {
|
|
f := newFake(t)
|
|
states := newStates()
|
|
m := moduleWith(t, f, states)
|
|
if _, err := tool(t, m, FetchTool)(args); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if st := states.waitEnd(t); st.State != delivery.StepFailed {
|
|
t.Errorf("%s: step = %+v, want failed", name, st)
|
|
}
|
|
}
|
|
}
|