Skip to content

Commit

Permalink
test suite (#126)
Browse files Browse the repository at this point in the history
* add some ignored things

* use go 1.20

* go mod tidy

* fix deprecated stdlib APIs from minor version releases cause thats totally cool and normal

* fix deprecated flake output

* here wigo

* full nodejs which-language testing

* more tests

* another test, cleanup

* move some things around, fix some fails

* fix testremove logic

* test guessing

* better test layout

* better search testing

* better info testing

* better add testing

* better remove testing

* better lock testing

* better install testing

* better list testing

* better guess testing

* add package managers to devshell for testing

* exclude test suite from upm src

* skip test suites that dont have tests

* cleanup

* add test-suite to ci

* add nix to test-suite task

* share nix store, run make generated

* fix dependencies list i think

* bleh

* dont go run statik just run statik

* i really hope directly invoking statik in the makefile works

* remove statik

* fix vendorhash

* embed.FS has different expectations to statik.FS

* lint

* fix statik->embed paths

* get rid of statik

* tweak semaphore test task

* try with self-hosted agent

* remove some stuff from ci

* oops

* use nix container image

* oops

* change image pull secret

* try this instead

* use just self-hosted

* install_nix script

* forgot to source nix

* forgot i dont need the brackets

* set semaphore cache backend

* set cache gcs bucket

* nocache

* make script more debuggable

* source the install_nix script

* publish test results

* go get gotestsum first

* try inline nix develop/shell

* use makefile for the tests

* fix golangci-lint invocation

* fix lint

* remove backend tests

* cleanup

* allowlist for upm derivation instead of blocklist

* go back to blocklist

* add test-suite command for local dev

* fix expected string
  • Loading branch information
cdmistman authored Oct 13, 2023
1 parent e9aaaaf commit 4b26922
Show file tree
Hide file tree
Showing 20 changed files with 1,017 additions and 98 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/cmd/upm/upm
/dist/
/internal/statik/
/packaging/aur/*.tar.gz
/packaging/aur/*.tar.xz
/packaging/aur/pkg/
Expand Down
20 changes: 20 additions & 0 deletions .semaphore/install_nix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env sh

set -e
set -o xtrace

install_script_cache_key="install-nix-2.16.1"
install_script="/tmp/$install_script_cache_key"

# Install Nix. Install the base version if the currently installed version is
# not what we expect.
if [ \
! -f ~/.nix-profile/etc/profile.d/nix.sh -o \
"$(~/.nix-profile/bin/nix --version)" != "nix (Nix) 2.16.1" \
]; then
curl -L https://releases.nixos.org/nix/nix-2.16.1/install | sh
fi

source ~/.nix-profile/etc/profile.d/nix.sh

set +e
116 changes: 22 additions & 94 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,121 +3,49 @@ version: v1.0
name: UPM
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
type: s1-goval

global_job_config:
env_vars:
- name: UPM_CI
value: "1"
prologue:
commands:
- checkout
- git switch --detach
- export PATH="/tmp:$PATH"
- source ./.semaphore/install_nix.sh

blocks:
- name: setup
dependencies: []
task:
jobs:
- name: cache nix installer
commands:
- >-
cache has_key nix-installer || (
curl
--proto '=https'
-o /tmp/nix-installer
--tlsv1.2 -sSf -L
https://github.com/DeterminateSystems/nix-installer/releases/download/v0.7.0/nix-installer-x86_64-linux
&& chmod +x /tmp/nix-installer
&& cache store nix-installer /tmp/nix-installer
)
# TODO: cache the dependencies of the nix package
# this might be possible based on exploratory:
# ```
# $ DERIVATION="$(nix path-info --derivation .)"
# $ declare -p DERIVATION
# $ nix-store --query --references "${DERIVATION}"
# ```
# The above spits out the deps of the derivation
# just have to filter out the `-source`
- name: cache golint-ci
commands:
- >-
cache has_key golangci-lint || (
mkdir -p bin &&
curl
-sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
| sh -s -- -b /tmp v1.52.2
&& cache store golangci-lint /tmp/golangci-lint
)
- name: build
dependencies: [ setup ]
dependencies: [ ]
task:
prologue:
commands:
- cache restore nix-installer
- sudo /tmp/nix-installer install linux --no-confirm --logger compact
- . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
jobs:
- name: nix
commands:
- cache restore nix-store
- nix build
- ./result/bin/upm --version
- cache store nix-store /nix
# TODO: get this working again
# - name: docker
# commands:
# - make light full

- name: lint
dependencies: [ setup ]

- name: test
dependencies: [ build ]
task:
jobs:
- name: golang lint
- name: test-suite
commands:
- make generated
- cache restore golangci-lint
- golangci-lint run
- nix develop -c nix shell -c make test-suite
epilogue:
commands:
- test-results publish junit.xml

- name: release
dependencies: [ build, lint ]
run:
# git tag can be eg 'v1.0', 'v1.0.1', 'v1.0-alpha', or 'v1.0-alpha-4'
when: "tag =~ 'v[0-9]+\.[0-9]+(\.[0-9]+)?(-.*)*'"
- name: lint
dependencies: [ ]
task:
prologue:
commands:
- cache restore dist
jobs:
- name: goreleaser
- name: golang lint
commands:
- make generated
- cache restore golangci-lint
- >-
cache has_key goreleaser || (
curl
--proto '=https'
-o /tmp/goreleaser
-sL https://git.io/goreleaser
&& chmod +x /tmp/goreleaser
&& cache store goreleaser /tmp/goreleaser
)
- cache restore goreleaser
- goreleaser --release-notes=<(scripts/extract-changelog.py)
# - name: snapcraft
# commands:
# - >-
# snapcraft login --with <(
# echo "$SNAPCRAFT_LOGIN_FILE" |
# base64 --decode --ignore-garbage
# )
# - scripts/upload-snap.bash
# - name: deploy
# commands:
# - >-
# echo "$DOCKER_PASSWORD" |
# docker login
# --username "$DOCKER_USERNAME"
# --password-stdin
# - make deploy
# - |
# git tag "semaphoreci_pipeline_"
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
| sh -s -- -b /tmp v1.52.2
- /tmp/golangci-lint run
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ help: ## Show this message
.PHONY: test
test:
go test ./... -v

.PHONY: test-suite
ifdef UPM_CI
test-suite:
go get gotest.tools/gotestsum
go run gotest.tools/gotestsum --junitfile ./junit.xml ./test-suite
else
test-suite:
nix develop -c nix shell -c go test ./test-suite
endif
2 changes: 1 addition & 1 deletion internal/backends/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var languageBackends = []api.LanguageBackend{
python.Python2Backend,
nodejs.BunBackend,
nodejs.NodejsNPMBackend,
nodejs.NodejsPNPMBackend,
nodejs.NodejsPNPMBackend,
nodejs.NodejsYarnBackend,
ruby.RubyBackend,
elisp.ElispBackend,
Expand Down
7 changes: 7 additions & 0 deletions nix/devshell/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
bun,
go,
mkShell,
nodejs,
nodePackages,
}:
mkShell {
name = "upm";
packages = [
bun
go
nodejs
nodePackages.pnpm
nodePackages.yarn
];
}
17 changes: 15 additions & 2 deletions nix/upm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
rev,
makeWrapper,
}:
buildGoModule {
buildGoModule rec {
pname = "upm";
version = rev;

src = ../../.;
src = builtins.path {
name = "${pname}-${version}-src";
path = ../../.;
filter = path: _: builtins.all (block: (builtins.baseNameOf path) != block) [
".github"
".semaphore"
"packaging"
"scripts"
"test-suite"
".goreleaser.yml"
".replit"
"replit.nix"
];
};

vendorHash = "sha256-2F2/BcHUEpbYxmAW1SsIBbn6U2VWinWjdxMvsbzfKsc=";

Expand Down
65 changes: 65 additions & 0 deletions test-suite/Add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package testSuite

import (
"testing"

testUtils "github.com/replit/upm/test-suite/utils"
)

func TestAdd(t *testing.T) {
for _, bt := range languageBackends {
bt.Start(t)

var pkgs []string
switch bt.Backend.Name {
default:
t.Run(bt.Backend.Name, func(t *testing.T) {
t.Skip("no test")
})
continue
}

bt.Subtest(bt.Backend.Name, func(bt testUtils.BackendT) {
doAdd(bt, pkgs...)
})
}
}

func doAdd(bt testUtils.BackendT, pkgs ...string) {
for _, tmpl := range standardTemplates {
template := bt.Backend.Name + "/" + tmpl + "/"
bt.Subtest(tmpl, func(bt testUtils.BackendT) {
if tmpl != "no-deps" {
bt.Subtest("locked", func(bt testUtils.BackendT) {
bt.Subtest("each", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
bt.AddTestFile(template+bt.Backend.Lockfile, bt.Backend.Lockfile)
for _, pkg := range pkgs {
bt.UpmAdd(pkg)
}
})

bt.Subtest("all", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
bt.AddTestFile(template+bt.Backend.Lockfile, bt.Backend.Lockfile)
bt.UpmAdd(pkgs...)
})
})
}

bt.Subtest("unlocked", func(bt testUtils.BackendT) {
bt.Subtest("each", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
for _, pkg := range pkgs {
bt.UpmAdd(pkg)
}
})

bt.Subtest("all", func(bt testUtils.BackendT) {
bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
bt.UpmAdd(pkgs...)
})
})
})
}
}
67 changes: 67 additions & 0 deletions test-suite/Guess_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package testSuite

import (
"io"
"strings"
"testing"

"github.com/replit/upm/test-suite/templates"
testUtils "github.com/replit/upm/test-suite/utils"
)

func TestGuess(t *testing.T) {
for _, bt := range languageBackends {
bt.Start(t)

tests := make(map[string]map[string][]string)
switch bt.Backend.Name {
default:
t.Run(bt.Backend.Name, func(t *testing.T) {
t.Skip("no test")
})
continue
}

for ext, guessSuites := range tests {
bt.Subtest(ext, func(bt testUtils.BackendT) {
for template, tests := range guessSuites {
bt.Subtest(template, func(bt testUtils.BackendT) {
for _, test := range tests {
testSrcFile := "guess/" + template + "/" + test

bt.Subtest(test, func(bt testUtils.BackendT) {
bt.AddTestFile(testSrcFile, test+"."+ext)
bt.AddTestFile(bt.Backend.Name+"/no-deps/"+bt.Backend.Specfile, bt.Backend.Specfile)

expectFile, err := templates.FS.Open(testSrcFile + ".expect")
if err != nil {
bt.Fail("No expect file found for %s: %v", testSrcFile, err)
}

var expectsText strings.Builder
_, err = io.Copy(&expectsText, expectFile)
if err != nil {
bt.Fail("Failed to read expect file for %s: %v", testSrcFile, err)
}

expects := strings.Split(strings.TrimSpace(expectsText.String()), "\n")

bt.UpmGuess(expects...)
})
}
})
}
})
}
}
}

var js = []string{
"basic",
"dedup",
"nested",
}

var ts = []string{
"typeImports",
}
Loading

0 comments on commit 4b26922

Please sign in to comment.