This commit introduces several maintenance improvements to the repository. - A `go.work` file has been added to define the workspace and make the project easier to work with. - The module path in `go.mod` has been updated to use a GitHub URL, and all import paths have been updated accordingly. - `examples` and `docs` directories have been created. - The `examples` directory contains scripts that demonstrate the tool's functionality. - The `docs` directory contains documentation for the project. - Tests have been added to the `pkg/github` package following the `_Good`, `_Bad`, `_Ugly` convention. - The missing `pkg/borg` package has been added to resolve a build error.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package github
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetPublicRepos_Good(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
w.Write([]byte(`[{"clone_url": "https://github.com/good/repo.git"}]`))
|
|
}))
|
|
defer server.Close()
|
|
|
|
repos, err := GetPublicReposWithAPIURL(server.URL, "good")
|
|
if err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
if len(repos) != 1 || repos[0] != "https://github.com/good/repo.git" {
|
|
t.Errorf("Expected one repo, got %v", repos)
|
|
}
|
|
}
|
|
|
|
func TestGetPublicRepos_Bad(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}))
|
|
defer server.Close()
|
|
|
|
_, err := GetPublicReposWithAPIURL(server.URL, "bad")
|
|
if err == nil {
|
|
t.Errorf("Expected an error, got nil")
|
|
}
|
|
}
|
|
|
|
func TestGetPublicRepos_Ugly(t *testing.T) {
|
|
_, err := GetPublicReposWithAPIURL("http://localhost", "")
|
|
if err == nil {
|
|
t.Errorf("Expected an error for empty user/org, got nil")
|
|
}
|
|
}
|