Skip to content

Commit

Permalink
test(github): add access_token default to test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephKav committed Jan 26, 2025
1 parent de6deac commit b012eb0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
36 changes: 32 additions & 4 deletions config/yaml_help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func testYAML_config_test(path string, t *testing.T) {

func testYAML_SomeNilServices(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
service:
a:
latest_version:
Expand Down Expand Up @@ -309,6 +313,10 @@ func testYAML_Ordering_1_no_services(path string, t *testing.T) {

func testYAML_Ordering_2_obscure_service_names(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
service:
"123":
latest_version:
Expand Down Expand Up @@ -357,6 +365,10 @@ func testYAML_Ordering_2_obscure_service_names(path string, t *testing.T) {

func testYAML_Ordering_3_empty_line_after_service_line(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
service:
C:
Expand All @@ -380,6 +392,10 @@ func testYAML_Ordering_3_empty_line_after_service_line(path string, t *testing.T

func testYAML_Ordering_4_multiple_empty_lines_after_service_line(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
service:
` + strings.Repeat("\n", 3) + `
P:
Expand All @@ -403,17 +419,25 @@ func testYAML_Ordering_4_multiple_empty_lines_after_service_line(path string, t

func testYAML_Ordering_5_eof_is_service_line(path string, t *testing.T) {
data := test.TrimYAML(`
settings:
data:
database_file: test-ordering_5.db
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
settings:
data:
database_file: test-ordering_5.db
service:`)
service:`)

writeFile(path, data, t)
}

func testYAML_Ordering_6_no_services_after_service_line_another_block(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
service:
settings:
Expand All @@ -426,6 +450,10 @@ func testYAML_Ordering_6_no_services_after_service_line_another_block(path strin

func testYAML_Ordering_7_no_services_after_service_line(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
settings:
data:
database_file: test-ordering_5.db
Expand Down
6 changes: 2 additions & 4 deletions service/latest_version/types/github/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,11 @@ func (l *Lookup) createRequest(logFrom logutil.LogFrom) (*http.Request, error) {
// Set headers.
req.Header.Set("Connection", "close")
// Access Token.
accessToken := l.accessToken()
if accessToken != "" {
if accessToken := l.accessToken(); accessToken != "" {
req.Header.Set("Authorization", fmt.Sprintf("token %s", accessToken))
}
// Conditional requests - https://docs.github.com/en/rest/overview/resources-in-the-rest-api#conditional-requests.
eTag := l.data.ETag()
if eTag != "" {
if eTag := l.data.ETag(); eTag != "" {
req.Header.Set("If-None-Match", eTag)
}

Expand Down
3 changes: 3 additions & 0 deletions service/latest_version/types/github/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ func TestQuery(t *testing.T) {
try++
temporaryFailureInNameResolution = false
lookup := testLookup(false)
if strings.Contains(tc.overrides, "access_token: null") {
lookup.HardDefaults.AccessToken = ""
}
lookup.Status.ServiceID = &name
err := yaml.Unmarshal([]byte(tc.overrides), lookup)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion web/api/v1/yaml_help_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright [2024] [Argus]
// Copyright [2025] [Argus]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,10 @@ func writeFile(path string, data string) {

func testYAML_Argus(path string) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
settings:
data:
database_file: test-argus.db
Expand Down
6 changes: 5 additions & 1 deletion web/yaml_help_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright [2024] [Argus]
// Copyright [2025] [Argus]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,6 +34,10 @@ func writeFile(path string, data string, t *testing.T) {

func testYAML_Argus(path string, t *testing.T) {
data := test.TrimYAML(`
defaults:
service:
latest_version:
access_token: ` + os.Getenv("GITHUB_TOKEN") + `
settings:
data:
database_file: test-web.db
Expand Down

0 comments on commit b012eb0

Please sign in to comment.