add manifest tests
This commit is contained in:
		
					parent
					
						
							
								faf1c836eb
							
						
					
				
			
			
				commit
				
					
						6e13ac4d5f
					
				
			
		
					 1 changed files with 81 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -5,6 +5,7 @@ package sourcehut
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	webhook_model "code.gitea.io/gitea/models/webhook"
 | 
			
		||||
| 
						 | 
				
			
			@ -384,3 +385,83 @@ func TestSourcehutJSONPayload(t *testing.T) {
 | 
			
		|||
	require.NoError(t, err)
 | 
			
		||||
	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))
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue