ci(yay): add integration test framework (#2178)

* add integration test framework

* fix integration tests

* fix integration tests
This commit is contained in:
Jo 2023-05-22 23:38:02 +02:00 committed by GitHub
parent 39f0d4e9a1
commit fdcf6ef664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 218 additions and 2 deletions

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (

View File

@ -1,4 +1,5 @@
FROM docker.io/jguer/yay-builder:latest
LABEL maintainer="Jguer,docker@jguer.space"
ENV GO111MODULE=on
WORKDIR /app

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package completion
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package ialpm
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package dep
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package download
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package download
import (

View 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])
}
}

View File

@ -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{

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package intrange
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package news
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package pgp
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package query
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package query
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package query
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package settings
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package settings
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package settings
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package settings
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package parser
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package settings_test
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package text
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package upgrade
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package upgrade
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package upgrade
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package vcs
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (

View File

@ -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)

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (

View File

@ -1,3 +1,6 @@
//go:build !integration
// +build !integration
package main
import (