File: metadata_test.go

package info (click to toggle)
golang-github-mmcloughlin-avo 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,024 kB
  • sloc: xml: 71,029; asm: 14,862; sh: 194; makefile: 21; ansic: 11
file content (97 lines) | stat: -rw-r--r-- 2,205 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package thirdparty

import (
	"context"
	"flag"
	"testing"
	"time"

	"github.com/mmcloughlin/avo/internal/github"
	"github.com/mmcloughlin/avo/internal/test"
)

var update = flag.Bool("update", false, "update project metadata")

func TestSuiteFileMetadata(t *testing.T) {
	test.RequiresNetwork(t)
	ctx := context.Background()

	s, err := LoadSuiteFile("suite.json")
	if err != nil {
		t.Fatal(err)
	}

	g := github.NewClient(github.WithTokenFromEnvironment())

	for _, prj := range s.Projects {
		// Fetch metadata.
		r, err := g.Repository(ctx, prj.Repository.Owner, prj.Repository.Name)
		if err != nil {
			t.Fatal(err)
		}

		// Update, if requested.
		if *update {
			prj.DefaultBranch = r.DefaultBranch
			prj.Metadata.Description = r.Description
			prj.Metadata.Homepage = r.Homepage
			prj.Metadata.Stars = r.StargazersCount

			t.Logf("%s: metadata updated", prj.ID())
		}

		// Check up to date. Potentially fast-changing properties not included.
		uptodate := true
		uptodate = prj.DefaultBranch == r.DefaultBranch && uptodate
		uptodate = prj.Metadata.Description == r.Description && uptodate
		uptodate = prj.Metadata.Homepage == r.Homepage && uptodate

		if !uptodate {
			t.Errorf("%s: metadata out of date (use -update flag to fix)", prj.ID())
		}
	}

	if *update {
		s.MetadataLastUpdate = time.Now().UTC()
	}

	if err := StoreSuiteFile("suite.json", s); err != nil {
		t.Fatal(err)
	}
}

func TestSuiteFileKnownIssues(t *testing.T) {
	test.RequiresNetwork(t)
	ctx := context.Background()

	s, err := LoadSuiteFile("suite.json")
	if err != nil {
		t.Fatal(err)
	}

	g := github.NewClient(github.WithTokenFromEnvironment())

	for _, prj := range s.Projects {
		// Skipped packages must refer to an open issue.
		if !prj.Skip() {
			continue
		}

		if prj.KnownIssue == 0 {
			t.Errorf("%s: skipped package must refer to known issue", prj.ID())
		}

		issue, err := g.Issue(ctx, "mmcloughlin", "avo", prj.KnownIssue)
		if err != nil {
			t.Fatal(err)
		}

		if issue.State != "open" {
			t.Errorf("%s: known issue in %s state", prj.ID(), issue.State)
		}

		if prj.Reason() != issue.HTMLURL {
			t.Errorf("%s: expected skip reason to be the issue url %s", prj.ID(), issue.HTMLURL)
		}
	}
}