From ef9be2bda0a7cb5b6e7f85b517262a474f070227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lia=20Liao?= Date: Wed, 2 Feb 2022 15:57:43 -0300 Subject: [PATCH] add test --- .gitignore | 1 + README.md | 12 ++++++++++++ default.nix | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .gitignore create mode 100644 default.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/README.md b/README.md index e69de29..b0f21a6 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,12 @@ +# swh-ipfs-test + +Tests fetching some known-good data from IPFS, and fetching a SWHID. +Since we have no bridge, and IPFS doesn't understand SWHIDs (yet), we +currently test for this fetch to fail. + +``` +$ nix-build . -A driver +$ result/bin/nixos-test-driver +``` + +and call the Python function `test_script()`. \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..a0ec12a --- /dev/null +++ b/default.nix @@ -0,0 +1,51 @@ +let + pkgs = import (builtins.fetchGit { + name = "pinned-nixpkgs-21.11"; + url = "https://github.com/NixOS/nixpkgs/"; + ref = "refs/heads/nixos-21.11"; + rev = "860b56be91fb874d48e23a950815969a7b832fbc"; + }) {}; + + # TODO: This is where I'd put our IPFS plugin (if we had one!!) + ipfs = pkgs.ipfs; + + # CID representing the SWHID + # https://archive.softwareheritage.org/browse/snapshot/c7c108084bc0bf3d81436bf980b46e98bd338453/directory/ + # (no particular attachment to darkroom, it was just the example + # snapshot from the SWHID docs) + swhid_cid = "znDfqECWqk8VqwNL2ayyYnvJdwDN9qYqa2"; + + # CID pointing to GNU Hello on Git (taken from the Nix-IPFS + # integration docs) + known_good_cid = "baf4bcfgi2up65zpzhg2fmyi52kecqfhsaevbaha"; +in + + pkgs.nixosTest { + system = "x86_64-linux"; + machine = { config, pkgs, ... }: { + networking.firewall.enable = false; + services.ipfs = { + enable = true; + apiAddress = "/ip4/127.0.0.1/tcp/2324"; + }; + }; + skipLint = true; + + # TODO: Add bridge node (when we have a bridge) + testScript = '' + import json + import sys + + machine.wait_for_unit('ipfs') + print(machine.wait_until_succeeds('ipfs swarm peers | grep ip4')) + + machine.succeed( + 'ipfs --api /ip4/127.0.0.1/tcp/2324 dag get "${known_good_cid}"' + ) + + # Hangs forever because IPFS doesn't understand our CID + machine.fail( + 'timeout 5 ipfs dag get ${swhid_cid}' + ) + ''; + }