Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Make stable apitest for latest versions (#5)
Browse files Browse the repository at this point in the history
Closes #21

Resolves #12

Do not address #10 in this commit

---

* Ignore cache when running API tests

* Fix a typo

* Make stable API test with regexp matches

* Bump flake hash

* Implement snapshot recorder

Resolves #12

* Bump selfup to v1.x

* `git ls-files '.github/workflows/*.yml' | xargs nix run github:kachick/selfup/v1.1.2 -- run`

* setup-task is GPL3

* Add missing commit steps

* Fix reusing branch name

* Add missing checkout parameter

* Fill mandatory body option

* Fix if syntax
  • Loading branch information
kachick authored May 10, 2024
1 parent 94b16ea commit f82035b
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 42 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/bump-flake-lock-and-selfup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ on:

jobs:
bump:
uses: kachick/selfup/.github/workflows/reusable-bump-flake-lock-and-selfup.yml@action-v1
uses: kachick/selfup/.github/workflows/reusable-bump-flake-lock-and-selfup.yml@v1.1.2
with:
dry-run: ${{ github.event_name == 'pull_request' }}
pr-title: 'Bump flake.lock and related dependencies'
optional-run: |
echo 'Add another changes and git commit here, especially for .node-version/.ruby-version'
secrets:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/ci-googleapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- run: go test -tags=apitest ./...
- run: go test -count=1 -tags=apitest ./...
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
with:
# https://spdx.org/licenses/
allow-licenses: MIT, BSD-3-Clause, BSD-2-Clause, 0BSD, Unlicense, ISC, Apache-2.0, CC-BY-4.0
allow-dependencies-licenses: pkg:githubactions/DeterminateSystems/nix-installer-action
allow-dependencies-licenses: pkg:githubactions/DeterminateSystems/nix-installer-action, pkg:githubactions/arduino/setup-task
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
- uses: actions/checkout@v4
- uses: dprint/check@v2.2
with:
dprint-version: '0.45.1' # selfup { "regex": "\\d[^']+", "script": "dprint --version | cut -d ' ' -f 2" }
dprint-version: '0.45.1' # selfup {"extract":"\\d[^']+","replacer":["dprint", "--version"], "nth": 2}

typos:
timeout-minutes: 15
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@v1.21.0 # selfup { "regex": "\\d\\.\\d+\\.\\d+", "script": "typos --version | cut -d ' ' -f 2" }
- uses: crate-ci/typos@v1.21.0 # selfup {"extract":"\\d\\.\\d+\\.\\d+","replacer":["typos", "--version"], "nth": 2}
with:
files: |
.
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 📸

on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
schedule:
# Every 10:42 JST
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
- cron: '42 1 * * *'
workflow_dispatch:

jobs:
bump_snapshot:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
# Needed to get commit counts
# https://stackoverflow.com/a/65056108
fetch-depth: 0
- name: Prepare Git user
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Prepare Git branch
id: prepare-branch
run: |
pr_branch="${{ github.sha }}-$(date +%Y%m%d-%H%M%S)"
git switch -c "${pr_branch}"
echo pr_branch="$pr_branch" | tee -a "$GITHUB_OUTPUT"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Install Task
uses: arduino/setup-task@v2
with:
version: '3.36.0' # selfup {"extract":"\\d\\.\\d+\\.\\d+","replacer":["task", "--version"], "nth": 3}
- run: |
task snapshot | tee -a snapshot.txt
- name: Update related CI dependencies
run: |
git diff-index --quiet HEAD || git commit -m 'Update snapshots' snapshot.txt
- name: Count added commits
id: count-commits
run: |
count="$(git rev-list --count origin/${{ github.event.repository.default_branch }}..)"
echo "count=${count}" | tee -a "$GITHUB_OUTPUT"
- name: Push branch
run: git push origin '${{ steps.prepare-branch.outputs.pr_branch }}'
if: github.event_name != 'pull_request' && (steps.count-commits.outputs.count > 0)
- name: Create PR
if: github.event_name != 'pull_request' && (steps.count-commits.outputs.count > 0)
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh pr create --base '${{ github.event.repository.default_branch }}' --title 'Update snapshots' --body 'Update snapshots'
6 changes: 5 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tasks:
- go test ./...
test-all:
cmds:
- go test -tags=apitest ./...
- go test -count=1 -tags=apitest ./...
fmt:
cmds:
- dprint fmt
Expand All @@ -31,6 +31,10 @@ tasks:
- dprint check
- typos . .github .vscode
- nixpkgs-fmt --check ./*.nix
snapshot:
cmds:
- go run ./cmd/gwurl 'https://dl.google.com/tag/s/appguid%3D%7BDDCCD2A9-025E-4142-BCEB-F467B88CF830%7D%26iid%3D%7BBF6725E7-4A15-87B7-24D5-0ADABEC753EE%7D%26lang%3Dja%26browser%3D4%26usagestats%3D0%26appname%3DGoogle%2520%25E6%2597%25A5%25E6%259C%25AC%25E8%25AA%259E%25E5%2585%25A5%25E5%258A%259B%26needsadmin%3Dtrue%26ap%3Dexternal-stable-universal/japanese-ime/GoogleJapaneseInputSetup.exe' | sort
- go run ./cmd/gwurl 'https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B69ED4A6C-1B6F-4C8F-9298-FC4A61FC55C4%7D%26lang%3Dja%26browser%3D3%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dprefers%26ap%3Dx64-statsdef_1%26installdataindex%3Dempty/update2/installers/ChromeSetup.exe' | sort
deps:
cmds:
- nix --version
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# When updating go.mod or go.sum, update this sha together as following
# vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
# (`pkgs.lib.fakeSha256` returns invalid string in thesedays... :<)
vendorHash = "sha256-hC1eg2mC3Qp0QGFj3pTMIOyjrMV9Yx+hqvupxUG17OQ=";
vendorHash = "sha256-i07qu5jt4XTD2YxorJlAY/Kq1zk4yfiUSlSr3toBBGA=";
};

packages.default = packages.gwurl;
Expand Down
53 changes: 20 additions & 33 deletions internal/googleapi/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@
package googleapi

import (
"strings"
"regexp"
"slices"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

func TestPostGoogleAPI(t *testing.T) {
testCases := []struct {
description string
input App
want []string
want string
ok bool
}{
{
Expand All @@ -24,45 +22,39 @@ func TestPostGoogleAPI(t *testing.T) {
Appid: "{DDCCD2A9-025E-4142-BCEB-F467B88CF830}",
Ap: "external-stable-universal",
},
want: []string{
"http://edgedl.me.gvt1.com/edgedl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi",
"https://edgedl.me.gvt1.com/edgedl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi",
"http://dl.google.com/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi",
"https://dl.google.com/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi",
"http://www.google.com/dl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi",
"https://www.google.com/dl/release2/kjspmop3m4hu2sbbaotsynsgja_2.29.5370.0/GoogleJapaneseInput64-2.29.5370.0.msi",
},
ok: true,
want: "https?://[a-zA-Z0-9/.-]+_[0-9.]+/GoogleJapaneseInput[a-zA-Z0-9/.-]+\\.(exe|msi)",
ok: true,
},
{
description: "Google Chrome",
input: App{
Appid: "{8A69D345-D564-463C-AFF1-A69D9E530F96}",
Ap: "x64-stable-statsdef_1",
},
want: []string{
"http://edgedl.me.gvt1.com/edgedl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe",
"https://edgedl.me.gvt1.com/edgedl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe",
"http://dl.google.com/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe",
"https://dl.google.com/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe",
"http://www.google.com/dl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe",
"https://www.google.com/dl/release2/chrome/acerbjgcqxawfznuerhowwbwv36a_124.0.6367.156/124.0.6367.156_chrome_installer.exe",
},
ok: true,
want: "https?://[a-zA-Z0-9/\\.-]+_[0-9\\.]+/[a-zA-Z0-9/\\.-]+_chrome_installer\\.(exe|msi)",
ok: true,
},
{
description: "Unknown Prams",
description: "Unknown parameters",
input: App{
Appid: "foo",
Ap: "bar",
},
want: nil,
ok: false,
ok: false,
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
var wantPattern *regexp.Regexp
var err error
if tc.ok {
wantPattern, err = regexp.Compile(tc.want)
if err != nil {
t.Fatalf("unexpected error happened: %v", err)
}
}

resp, err := PostGoogleAPI(Os{
Platform: "win",
Version: "10",
Expand All @@ -88,13 +80,8 @@ func TestPostGoogleAPI(t *testing.T) {
if !tc.ok {
t.Fatalf("expected error did not happen")
}

dictComp := func(a string, b string) bool {
return strings.Compare(a, b) == -1
}

if diff := cmp.Diff(tc.want, urls, cmpopts.SortSlices(dictComp)); diff != "" {
t.Errorf("wrong result: %s", diff)
if slices.ContainsFunc(urls, func(u string) bool { return !wantPattern.MatchString(u) }) {
t.Errorf("returned urls contain unexpected pattern: %v", urls)
}
})
}
Expand Down
Empty file added snapshot.txt
Empty file.

0 comments on commit f82035b

Please sign in to comment.