mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
feat: add integration tests and GitHub Actions CI
Add integration test files for all providers (apt, dpkg, pacman, apk, dnf, rpm, flatpak, snap, pkg, detect) behind the 'integration' build tag. Tests exercise real package operations: update, search, info, install, verify, list, remove, and capability interfaces. Add GitHub Actions workflow running unit tests on ubuntu-latest and integration tests on Debian, Ubuntu, Fedora, Alpine, Arch Linux, and Ubuntu+Flatpak containers/runners.
This commit is contained in:
80
pkg/pkg_integration_test.go
Normal file
80
pkg/pkg_integration_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
//go:build integration
|
||||
|
||||
package pkg_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/gogrlx/snack"
|
||||
"github.com/gogrlx/snack/pkg"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIntegration_Pkg(t *testing.T) {
|
||||
mgr := pkg.New()
|
||||
if !mgr.Available() {
|
||||
t.Skip("pkg not available")
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("Update", func(t *testing.T) {
|
||||
err := mgr.Update(ctx)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Search", func(t *testing.T) {
|
||||
pkgs, err := mgr.Search(ctx, "curl")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, pkgs)
|
||||
})
|
||||
|
||||
t.Run("Info", func(t *testing.T) {
|
||||
p, err := mgr.Info(ctx, "curl")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, p)
|
||||
assert.Equal(t, "curl", p.Name)
|
||||
})
|
||||
|
||||
t.Run("Install", func(t *testing.T) {
|
||||
err := mgr.Install(ctx, snack.Targets("tree"), snack.WithSudo(), snack.WithAssumeYes())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("IsInstalled", func(t *testing.T) {
|
||||
installed, err := mgr.IsInstalled(ctx, "tree")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, installed)
|
||||
})
|
||||
|
||||
t.Run("Version", func(t *testing.T) {
|
||||
ver, err := mgr.Version(ctx, "tree")
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, ver)
|
||||
})
|
||||
|
||||
t.Run("List", func(t *testing.T) {
|
||||
pkgs, err := mgr.List(ctx)
|
||||
require.NoError(t, err)
|
||||
found := false
|
||||
for _, p := range pkgs {
|
||||
if p.Name == "tree" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, found, "tree should be in installed list")
|
||||
})
|
||||
|
||||
t.Run("Remove", func(t *testing.T) {
|
||||
err := mgr.Remove(ctx, snack.Targets("tree"), snack.WithSudo(), snack.WithAssumeYes())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("IsInstalled_After_Remove", func(t *testing.T) {
|
||||
installed, err := mgr.IsInstalled(ctx, "tree")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, installed)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user