add manifest tests

This commit is contained in:
oliverpool 2025-01-01 11:31:49 +01:00
parent faf1c836eb
commit 6e13ac4d5f

View file

@ -5,6 +5,7 @@ package sourcehut
import ( import (
"context" "context"
"strings"
"testing" "testing"
webhook_model "code.gitea.io/gitea/models/webhook" webhook_model "code.gitea.io/gitea/models/webhook"
@ -384,3 +385,83 @@ func TestSourcehutJSONPayload(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "json test", body.Variables.Note) assert.Equal(t, "json test", body.Variables.Note)
} }
func TestSourcehutAdjustManifest(t *testing.T) {
defer test.MockVariableValue(&setting.AppURL, "https://example.forgejo.org/")()
t.Run("without sources", func(t *testing.T) {
repo := &api.Repository{
CloneURL: "http://localhost:3000/testdata/repo.git",
}
manifest, err := adjustManifest(repo, "58771003157b81abc6bf41df0c5db4147a3e3c83", "refs/heads/main", strings.NewReader(`image: alpine/edge
tasks:
- say-hello: |
echo hello
- say-world: echo world`), ".build.yml")
require.NoError(t, err)
assert.Equal(t, `sources:
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
environment:
BUILD_SUBMITTER: forgejo
BUILD_SUBMITTER_URL: https://example.forgejo.org/
GIT_REF: refs/heads/main
image: alpine/edge
tasks:
- say-hello: |
echo hello
- say-world: echo world
`, string(manifest))
})
t.Run("with other sources", func(t *testing.T) {
repo := &api.Repository{
CloneURL: "http://localhost:3000/testdata/repo.git",
}
manifest, err := adjustManifest(repo, "58771003157b81abc6bf41df0c5db4147a3e3c83", "refs/heads/main", strings.NewReader(`image: alpine/edge
sources:
- http://other.example.conm/repo.git
tasks:
- hello: echo world`), ".build.yml")
require.NoError(t, err)
assert.Equal(t, `sources:
- http://other.example.conm/repo.git
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
environment:
BUILD_SUBMITTER: forgejo
BUILD_SUBMITTER_URL: https://example.forgejo.org/
GIT_REF: refs/heads/main
image: alpine/edge
tasks:
- hello: echo world
`, string(manifest))
})
t.Run("with same source", func(t *testing.T) {
repo := &api.Repository{
CloneURL: "http://localhost:3000/testdata/repo.git",
}
manifest, err := adjustManifest(repo, "58771003157b81abc6bf41df0c5db4147a3e3c83", "refs/heads/main", strings.NewReader(`image: alpine/edge
sources:
- http://localhost:3000/testdata/repo.git
- http://other.example.conm/repo.git
tasks:
- hello: echo world`), ".build.yml")
require.NoError(t, err)
assert.Equal(t, `sources:
- http://localhost:3000/testdata/repo.git#58771003157b81abc6bf41df0c5db4147a3e3c83
- http://other.example.conm/repo.git
environment:
BUILD_SUBMITTER: forgejo
BUILD_SUBMITTER_URL: https://example.forgejo.org/
GIT_REF: refs/heads/main
image: alpine/edge
tasks:
- hello: echo world
`, string(manifest))
})
}