mirror of
https://github.com/Jguer/yay.git
synced 2024-11-06 00:57:21 +01:00
ci(yay): add integration test framework (#2178)
* add integration test framework * fix integration tests * fix integration tests
This commit is contained in:
parent
39f0d4e9a1
commit
fdcf6ef664
8
.github/workflows/testing.yml
vendored
8
.github/workflows/testing.yml
vendored
@ -20,3 +20,11 @@ jobs:
|
||||
run: /app/bin/golangci-lint run ./...
|
||||
- name: Run Build and Tests
|
||||
run: make test
|
||||
- name: Run Integration Tests
|
||||
continue-on-error: true
|
||||
run: |
|
||||
useradd -m yay &&
|
||||
chown -R yay:yay . &&
|
||||
cp -r ~/go/ /home/yay/go/ &&
|
||||
chown -R yay:yay /home/yay/go/ &&
|
||||
su yay -c "make test-integration"
|
||||
|
@ -1,5 +1,5 @@
|
||||
FROM docker.io/jguer/yay-builder:latest
|
||||
LABEL maintainer="Jguer,joaogg3 at google mail"
|
||||
LABEL maintainer="Jguer,docker@jguer.space"
|
||||
|
||||
ARG VERSION
|
||||
ARG PREFIX
|
||||
|
4
Makefile
4
Makefile
@ -53,6 +53,10 @@ test_lint: test lint
|
||||
test:
|
||||
$(GO) test -race -covermode=atomic $(FLAGS) ./...
|
||||
|
||||
.PHONY: test-integration
|
||||
test-integration:
|
||||
$(GO) test -tags=integration $(FLAGS) ./...
|
||||
|
||||
.PHONY: build
|
||||
build: $(BIN)
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,4 +1,5 @@
|
||||
FROM docker.io/jguer/yay-builder:latest
|
||||
LABEL maintainer="Jguer,docker@jguer.space"
|
||||
|
||||
ENV GO111MODULE=on
|
||||
WORKDIR /app
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package completion
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package ialpm
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package dep
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
|
105
pkg/download/unified_integration_test.go
Normal file
105
pkg/download/unified_integration_test.go
Normal file
@ -0,0 +1,105 @@
|
||||
//go:build integration
|
||||
// +build integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/Jguer/aur"
|
||||
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
func TestIntegrationPKGBUILDReposDefinedDBClone(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"core/linux", "yay-bin", "yay-git"}
|
||||
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
cmdRunner := &exe.OSRunner{Log: testLogger}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "git",
|
||||
GitFlags: []string{},
|
||||
Log: testLogger,
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"linux": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"core/linux": true, "yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
func TestIntegrationPKGBUILDReposNotExist(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil // fakes a package found for all
|
||||
},
|
||||
}
|
||||
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
cmdRunner := &exe.OSRunner{Log: testLogger}
|
||||
cmdBuilder := &exe.CmdBuilder{
|
||||
Runner: cmdRunner,
|
||||
GitBin: "git",
|
||||
GitFlags: []string{},
|
||||
Log: testLogger,
|
||||
}
|
||||
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"yay": "core"},
|
||||
}
|
||||
cloned, err := PKGBUILDRepos(context.Background(), searcher, mockClient,
|
||||
cmdBuilder,
|
||||
targets, parser.ModeAny, "https://aur.archlinux.org", dir, false)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.EqualValues(t, map[string]bool{"yay-bin": true, "yay-git": true}, cloned)
|
||||
}
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
// WHEN defining as specified targets
|
||||
// THEN all aur be found and cloned
|
||||
func TestIntegrationPKGBUILDFull(t *testing.T) {
|
||||
mockClient := &mockaur.MockAUR{
|
||||
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
|
||||
return []aur.Pkg{{}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
targets := []string{"core/linux", "aur/yay-bin", "yay-git"}
|
||||
searcher := &testDBSearcher{
|
||||
absPackagesDB: map[string]string{"linux": "core"},
|
||||
}
|
||||
|
||||
fetched, err := PKGBUILDs(searcher, mockClient, &http.Client{},
|
||||
targets, "https://aur.archlinux.org", parser.ModeAny)
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
for _, target := range targets {
|
||||
assert.Contains(t, fetched, target)
|
||||
assert.NotEmpty(t, fetched[target])
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package download
|
||||
|
||||
import (
|
||||
@ -5,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -15,6 +19,7 @@ import (
|
||||
mockaur "github.com/Jguer/yay/v12/pkg/dep/mock"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/exe"
|
||||
"github.com/Jguer/yay/v12/pkg/settings/parser"
|
||||
"github.com/Jguer/yay/v12/pkg/text"
|
||||
)
|
||||
|
||||
// GIVEN 2 aur packages and 1 in repo
|
||||
@ -31,6 +36,8 @@ func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testLogger := text.NewLogger(os.Stdout, os.Stderr, strings.NewReader(""), true, "test")
|
||||
|
||||
os.MkdirAll(filepath.Join(dir, "yay", ".git"), 0o777)
|
||||
|
||||
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
||||
@ -42,6 +49,7 @@ func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
||||
Runner: cmdRunner,
|
||||
GitBin: "/usr/local/bin/git",
|
||||
GitFlags: []string{},
|
||||
Log: testLogger,
|
||||
},
|
||||
}
|
||||
searcher := &testDBSearcher{
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package intrange
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package news
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package pgp
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package parser
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package settings_test
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package text
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package upgrade
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package vcs
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -27,7 +30,7 @@ import (
|
||||
func TestPrintUpdateList(t *testing.T) {
|
||||
// The current method of capturing os.Stdout hinders parallelization.
|
||||
// Setting of global settings.NoConfirm in printUpdateList also hinders parallelization.
|
||||
//t.Parallel()
|
||||
// t.Parallel()
|
||||
pacmanBin := t.TempDir() + "/pacman"
|
||||
f, err := os.OpenFile(pacmanBin, os.O_RDONLY|os.O_CREATE, 0o755)
|
||||
require.NoError(t, err)
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,3 +1,6 @@
|
||||
//go:build !integration
|
||||
// +build !integration
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
Loading…
Reference in New Issue
Block a user