This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
generated from kachick/anylang-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ on: | |
- '**.go' | ||
- 'go.*' | ||
- 'testdata/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: 📡 | ||
|
||
on: | ||
# This test actually send request to Google API, so do not add frequently triggers as push/PR | ||
schedule: | ||
# Every 10:42 JST | ||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule | ||
- cron: '42 1 * * *' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test-actual-api: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache-dependency-path: 'go.sum' | ||
- run: go test -tags=apitest ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,8 @@ | |
"command": ["nixpkgs-fmt"] | ||
} | ||
} | ||
}, | ||
"gopls": { | ||
"build.buildFlags": ["-tags=apitest"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//go:build apitest | ||
// +build apitest | ||
|
||
package googleapi | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
) | ||
|
||
func TestPostGoogleAPI(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
input GoogleApiApp | ||
want []string | ||
ok bool | ||
}{ | ||
{ | ||
description: "Google Japanese IME", | ||
input: GoogleApiApp{ | ||
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, | ||
}, | ||
{ | ||
description: "Google Chrome", | ||
input: GoogleApiApp{ | ||
Appid: "{8A69D345-D564-463C-AFF1-A69D9E530F96}", | ||
Ap: "x64-stable-statsdef_1", | ||
}, | ||
want: []string{ | ||
"http://edgedl.me.gvt1.com/edgedl/release2/chrome/adno2uyj7yhsdmrqsizskbq3um2q_122.0.6261.129/122.0.6261.129_chrome_installer.exe", | ||
"https://edgedl.me.gvt1.com/edgedl/release2/chrome/adno2uyj7yhsdmrqsizskbq3um2q_122.0.6261.129/122.0.6261.129_chrome_installer.exe", | ||
"http://dl.google.com/release2/chrome/adno2uyj7yhsdmrqsizskbq3um2q_122.0.6261.129/122.0.6261.129_chrome_installer.exe", | ||
"https://dl.google.com/release2/chrome/adno2uyj7yhsdmrqsizskbq3um2q_122.0.6261.129/122.0.6261.129_chrome_installer.exe", | ||
"http://www.google.com/dl/release2/chrome/adno2uyj7yhsdmrqsizskbq3um2q_122.0.6261.129/122.0.6261.129_chrome_installer.exe", | ||
"https://www.google.com/dl/release2/chrome/adno2uyj7yhsdmrqsizskbq3um2q_122.0.6261.129/122.0.6261.129_chrome_installer.exe", | ||
}, | ||
ok: true, | ||
}, | ||
{ | ||
description: "Unknown Prams", | ||
input: GoogleApiApp{ | ||
Appid: "foo", | ||
Ap: "bar", | ||
}, | ||
want: nil, | ||
ok: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.description, func(t *testing.T) { | ||
resp, err := PostGoogleAPI(GoogleApiOs{ | ||
Platform: "win", | ||
Version: "10", | ||
Architecture: "x64", | ||
}, tc.input) | ||
if err != nil { | ||
if tc.ok { | ||
t.Errorf("unexpected error happned: %v", err) | ||
return | ||
} else { | ||
return | ||
} | ||
} | ||
|
||
urls, err := GetPermalinks(resp) | ||
if err != nil { | ||
if tc.ok { | ||
t.Errorf("unexpected error happned: %v", err) | ||
return | ||
} else { | ||
return | ||
} | ||
} | ||
|
||
if !tc.ok { | ||
t.Errorf("expected error did not happen") | ||
return | ||
} | ||
|
||
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) | ||
} | ||
}) | ||
} | ||
} |