|
| 1 | +package version |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "regexp" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +func TestPackagingPinsReleaseRepo(t *testing.T) { |
| 13 | + root := repoRoot(t) |
| 14 | + files := []string{ |
| 15 | + filepath.Join("bucket", "squad-oc.json"), |
| 16 | + filepath.Join("Formula", "squad-oc.rb"), |
| 17 | + filepath.Join("packaging", "winget", "xeaser.squad-oc.yaml"), |
| 18 | + } |
| 19 | + repoURL := "https://github.com/" + Repo |
| 20 | + asset := regexp.MustCompile(Name + `_\d+\.\d+\.\d+_(windows_amd64\.zip|darwin_(amd64|arm64)\.tar\.gz|linux_(amd64|arm64)\.tar\.gz)`) |
| 21 | + for _, rel := range files { |
| 22 | + body, err := os.ReadFile(filepath.Join(root, rel)) |
| 23 | + if err != nil { |
| 24 | + t.Fatalf("%s: %v", rel, err) |
| 25 | + } |
| 26 | + s := string(body) |
| 27 | + if !strings.Contains(s, Repo) { |
| 28 | + t.Errorf("%s: missing repo %q", rel, Repo) |
| 29 | + } |
| 30 | + if !strings.Contains(s, repoURL) { |
| 31 | + t.Errorf("%s: missing %s", rel, repoURL) |
| 32 | + } |
| 33 | + if !asset.MatchString(s) { |
| 34 | + t.Errorf("%s: missing goreleaser asset name", rel) |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + raw, err := os.ReadFile(filepath.Join(root, "bucket", "squad-oc.json")) |
| 39 | + if err != nil { |
| 40 | + t.Fatal(err) |
| 41 | + } |
| 42 | + var scoop struct { |
| 43 | + Checkver string `json:"checkver"` |
| 44 | + Autoupdate struct { |
| 45 | + Hash struct { |
| 46 | + URL string `json:"url"` |
| 47 | + } `json:"hash"` |
| 48 | + } `json:"autoupdate"` |
| 49 | + } |
| 50 | + if err := json.Unmarshal(raw, &scoop); err != nil { |
| 51 | + t.Fatalf("scoop manifest: %v", err) |
| 52 | + } |
| 53 | + if scoop.Checkver != "github" { |
| 54 | + t.Fatalf("scoop checkver = %q, want github", scoop.Checkver) |
| 55 | + } |
| 56 | + if !strings.Contains(scoop.Autoupdate.Hash.URL, Repo+"/releases/download/") || !strings.HasSuffix(scoop.Autoupdate.Hash.URL, "checksums.txt") { |
| 57 | + t.Fatalf("scoop autoupdate hash url = %q", scoop.Autoupdate.Hash.URL) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +func TestUserDocsDoNotLeadWithGoBuild(t *testing.T) { |
| 62 | + root := repoRoot(t) |
| 63 | + for _, rel := range []string{ |
| 64 | + filepath.Join("docs", "get-started.md"), |
| 65 | + filepath.Join("docs", "workshop", "README.md"), |
| 66 | + } { |
| 67 | + body, err := os.ReadFile(filepath.Join(root, rel)) |
| 68 | + if err != nil { |
| 69 | + t.Fatal(err) |
| 70 | + } |
| 71 | + if strings.Contains(string(body), "go build") { |
| 72 | + t.Errorf("%s: go build belongs in Develop/CONTRIBUTING only", rel) |
| 73 | + } |
| 74 | + } |
| 75 | + readme, err := os.ReadFile(filepath.Join(root, "README.md")) |
| 76 | + if err != nil { |
| 77 | + t.Fatal(err) |
| 78 | + } |
| 79 | + s := string(readme) |
| 80 | + dev := strings.Index(s, "## Develop") |
| 81 | + if dev < 0 { |
| 82 | + t.Fatal("README missing ## Develop") |
| 83 | + } |
| 84 | + if strings.Contains(s[:dev], "go build") { |
| 85 | + t.Error("README leads with go build") |
| 86 | + } |
| 87 | + if !strings.Contains(s[dev:], "go build") { |
| 88 | + t.Error("README Develop should keep go build") |
| 89 | + } |
| 90 | +} |
0 commit comments