mirror of
https://github.com/peridotbuild/peridot.git
synced 2024-12-03 18:16:25 +00:00
Add Forge Cacher tests
This commit is contained in:
parent
19a3a9fdd8
commit
392be966fd
@ -1,4 +1,4 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "forge",
|
||||
@ -10,3 +10,14 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/github.com/go-git/go-git/v5/plumbing/transport"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "forge_test",
|
||||
size = "small",
|
||||
srcs = ["caching_test.go"],
|
||||
embed = [":forge"],
|
||||
deps = [
|
||||
"//vendor/github.com/go-git/go-git/v5/plumbing/transport/http",
|
||||
"//vendor/github.com/stretchr/testify/require",
|
||||
],
|
||||
)
|
||||
|
86
tools/mothership/worker_server/forge/caching_test.go
Normal file
86
tools/mothership/worker_server/forge/caching_test.go
Normal file
@ -0,0 +1,86 @@
|
||||
package forge
|
||||
|
||||
import (
|
||||
transport_http "github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type testForge struct {
|
||||
Forge
|
||||
|
||||
callToGetAuthenticator int
|
||||
}
|
||||
|
||||
func (t *testForge) GetAuthenticator() (*Authenticator, error) {
|
||||
t.callToGetAuthenticator++
|
||||
return &Authenticator{
|
||||
AuthMethod: &transport_http.BasicAuth{
|
||||
Username: "test",
|
||||
Password: "test",
|
||||
},
|
||||
AuthorName: "test",
|
||||
AuthorEmail: "test@resf.org",
|
||||
Expires: time.Now().Add(time.Minute * 45),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestNewCacher(t *testing.T) {
|
||||
f := &testForge{}
|
||||
fAuth, err := f.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
fAuthAuthMethod := fAuth.AuthMethod.(*transport_http.BasicAuth)
|
||||
require.Equal(t, "test", fAuthAuthMethod.Username)
|
||||
require.Equal(t, "test", fAuthAuthMethod.Password)
|
||||
|
||||
c := NewCacher(f)
|
||||
cAuth, err := c.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
cAuthAuthMethod := cAuth.AuthMethod.(*transport_http.BasicAuth)
|
||||
require.Equal(t, "test", cAuthAuthMethod.Username)
|
||||
require.Equal(t, "test", cAuthAuthMethod.Password)
|
||||
}
|
||||
|
||||
func TestCacher_GetAuthenticator(t *testing.T) {
|
||||
f := &testForge{}
|
||||
c := NewCacher(f)
|
||||
|
||||
cAuth, err := c.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
cAuthAuthMethod := cAuth.AuthMethod.(*transport_http.BasicAuth)
|
||||
require.Equal(t, "test", cAuthAuthMethod.Username)
|
||||
require.Equal(t, "test", cAuthAuthMethod.Password)
|
||||
}
|
||||
|
||||
func TestCacher_GetAuthenticator_Cached(t *testing.T) {
|
||||
f := &testForge{}
|
||||
c := NewCacher(f)
|
||||
|
||||
cAuth, err := c.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "test", cAuth.AuthorName)
|
||||
|
||||
cAuth, err = c.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "test", cAuth.AuthorName)
|
||||
|
||||
require.Equal(t, 1, f.callToGetAuthenticator)
|
||||
}
|
||||
|
||||
func TestCacher_GetAuthenticator_Expired(t *testing.T) {
|
||||
f := &testForge{}
|
||||
c := NewCacher(f)
|
||||
|
||||
cAuth, err := c.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "test", cAuth.AuthorName)
|
||||
|
||||
cAuth.Expires = time.Now().Add(-time.Minute * 10)
|
||||
|
||||
cAuth, err = c.GetAuthenticator()
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, "test", cAuth.AuthorName)
|
||||
|
||||
require.Equal(t, 2, f.callToGetAuthenticator)
|
||||
}
|
@ -18,6 +18,7 @@ go_test(
|
||||
srcs = ["github_test.go"],
|
||||
embed = [":github"],
|
||||
deps = [
|
||||
"//vendor/github.com/go-git/go-git/v5/plumbing/transport/http",
|
||||
"//vendor/github.com/jarcoal/httpmock",
|
||||
"//vendor/github.com/stretchr/testify/require",
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user