The nixos_flake_info metric's current_rev label was incorrectly showing the nixpkgs input revision (from /run/current-system/nixos-version) instead of the flake's own revision. Now reads from /run/current-system/configuration-revision which contains the flake's self.rev when system.configurationRevision is set in the NixOS configuration. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package collector
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetCurrentSystemRevision(t *testing.T) {
|
|
// Skip if not on NixOS with system.configurationRevision set
|
|
if _, err := os.Stat(configRevisionPath); os.IsNotExist(err) {
|
|
t.Skip("not running on NixOS with system.configurationRevision set")
|
|
}
|
|
|
|
rev, err := getCurrentSystemRevision()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Just check it returns something reasonable
|
|
t.Logf("current system revision: %s", rev)
|
|
}
|
|
|
|
func TestFlakeLocksUnmarshal(t *testing.T) {
|
|
jsonData := `{
|
|
"revision": "abc1234567890",
|
|
"locks": {
|
|
"nodes": {
|
|
"nixpkgs": {
|
|
"locked": {
|
|
"lastModified": 1700000000,
|
|
"rev": "def4567890123",
|
|
"type": "github"
|
|
}
|
|
},
|
|
"home-manager": {
|
|
"locked": {
|
|
"lastModified": 1699000000,
|
|
"rev": "ghi7890123456",
|
|
"type": "github"
|
|
}
|
|
},
|
|
"root": {
|
|
"inputs": {
|
|
"nixpkgs": "nixpkgs",
|
|
"home-manager": "home-manager"
|
|
}
|
|
}
|
|
},
|
|
"root": "root"
|
|
}
|
|
}`
|
|
|
|
var data flakeMetadata
|
|
if err := json.Unmarshal([]byte(jsonData), &data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if data.Revision != "abc1234567890" {
|
|
t.Errorf("expected revision abc1234567890, got %s", data.Revision)
|
|
}
|
|
|
|
if len(data.Locks.Nodes) != 3 {
|
|
t.Errorf("expected 3 nodes, got %d", len(data.Locks.Nodes))
|
|
}
|
|
|
|
nixpkgs := data.Locks.Nodes["nixpkgs"]
|
|
if nixpkgs.Locked == nil {
|
|
t.Fatal("expected nixpkgs to have locked info")
|
|
}
|
|
if nixpkgs.Locked.LastModified != 1700000000 {
|
|
t.Errorf("expected lastModified 1700000000, got %d", nixpkgs.Locked.LastModified)
|
|
}
|
|
if nixpkgs.Locked.Rev != "def4567890123" {
|
|
t.Errorf("expected rev def4567890123, got %s", nixpkgs.Locked.Rev)
|
|
}
|
|
if nixpkgs.Locked.Type != "github" {
|
|
t.Errorf("expected type github, got %s", nixpkgs.Locked.Type)
|
|
}
|
|
}
|