-
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
8 changed files
with
362 additions
and
121 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 |
---|---|---|
@@ -1,9 +1,13 @@ | ||
# Please see the documentation for all configuration options: | ||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: "gomod" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
- package-ecosystem: gomod | ||
directory: / | ||
schedule: | ||
interval: daily | ||
|
||
- package-ecosystem: docker | ||
directory: / | ||
schedule: | ||
interval: "daily" | ||
interval: daily |
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,76 @@ | ||
package disk | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
// Helper function to reset environment variable | ||
resetEnv := func() { | ||
os.Unsetenv("YANDEX_DISK_ACCESS_TOKEN") | ||
} | ||
|
||
t.Run("With provided token", func(t *testing.T) { | ||
resetEnv() | ||
client := New("test-token") | ||
if client == nil { | ||
t.Fatal("Expected non-nil client") | ||
} | ||
if client.AccessToken != "test-token" { | ||
t.Errorf("Expected AccessToken to be 'test-token', got '%s'", client.AccessToken) | ||
} | ||
if client.HTTPClient == nil { | ||
t.Fatal("Expected non-nil HTTPClient") | ||
} | ||
if client.HTTPClient.Timeout != 10*time.Second { | ||
t.Errorf("Expected Timeout to be 10 seconds, got %v", client.HTTPClient.Timeout) | ||
} | ||
}) | ||
|
||
t.Run("With environment variable", func(t *testing.T) { | ||
resetEnv() | ||
os.Setenv("YANDEX_DISK_ACCESS_TOKEN", "env-token") | ||
client := New() | ||
if client == nil { | ||
t.Fatal("Expected non-nil client") | ||
} | ||
if client.AccessToken != "env-token" { | ||
t.Errorf("Expected AccessToken to be 'env-token', got '%s'", client.AccessToken) | ||
} | ||
}) | ||
|
||
t.Run("Without token and empty environment variable", func(t *testing.T) { | ||
resetEnv() | ||
client := New() | ||
if client != nil { | ||
t.Fatal("Expected nil client") | ||
} | ||
}) | ||
|
||
t.Run("With multiple tokens", func(t *testing.T) { | ||
resetEnv() | ||
client := New("token1", "token2") | ||
if client == nil { | ||
t.Fatal("Expected non-nil client") | ||
} | ||
if client.AccessToken != "token1" { | ||
t.Errorf("Expected AccessToken to be 'token1', got '%s'", client.AccessToken) | ||
} | ||
}) | ||
|
||
t.Run("HTTPClient configuration", func(t *testing.T) { | ||
resetEnv() | ||
client := New("test-token") | ||
if client == nil { | ||
t.Fatal("Expected non-nil client") | ||
} | ||
if client.HTTPClient == nil { | ||
t.Fatal("Expected non-nil HTTPClient") | ||
} | ||
if client.HTTPClient.Timeout != 10*time.Second { | ||
t.Errorf("Expected Timeout to be 10 seconds, got %v", client.HTTPClient.Timeout) | ||
} | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,31 +1,25 @@ | ||
package disk | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
) | ||
import "log" | ||
|
||
func prettyPrint(data interface{}) []byte { | ||
result, err := json.MarshalIndent(data, "", " ") | ||
if haveError(err) { | ||
log.Fatal(err) | ||
} | ||
return result | ||
} | ||
|
||
func haveError(err error) bool { | ||
// handleError is a helper function to handle errors | ||
// and exit the program if an error occurs | ||
func handleError(err error) { | ||
if err != nil { | ||
log.Fatal(err) | ||
return true | ||
log.Fatal("Error:", err) | ||
} | ||
return false | ||
} | ||
|
||
func inArray(n int, array []int) bool { | ||
if len(array) == 0 { | ||
return false | ||
} | ||
|
||
set := make(map[int]struct{}, len(array)) | ||
for _, b := range array { | ||
if b == n { | ||
return true | ||
} | ||
set[b] = struct{}{} | ||
} | ||
return false | ||
|
||
_, exists := set[n] | ||
return exists | ||
} |
Oops, something went wrong.