1
0
mirror of https://github.com/go-acme/lego.git synced 2025-01-03 15:23:32 +02:00

chore: remove useless tests (#2297)

This commit is contained in:
Ludovic Fernandez 2024-10-07 16:10:27 +02:00 committed by GitHub
parent b321d2be33
commit a6654a99c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 242 deletions

View File

@ -1,136 +0,0 @@
package transip
import (
"encoding/json"
"errors"
"fmt"
"time"
"github.com/transip/gotransip/v6/domain"
"github.com/transip/gotransip/v6/rest"
)
type dnsEntryWrapper struct {
DNSEntry domain.DNSEntry `json:"dnsEntry"`
}
type dnsEntriesWrapper struct {
DNSEntries []domain.DNSEntry `json:"dnsEntries"`
}
type fakeClient struct {
dnsEntries []domain.DNSEntry
setDNSEntriesLatency time.Duration
getInfoLatency time.Duration
domainName string
}
func (f *fakeClient) PutWithResponse(_ rest.Request) (rest.Response, error) {
panic("not implemented")
}
func (f *fakeClient) PostWithResponse(_ rest.Request) (rest.Response, error) {
panic("not implemented")
}
func (f *fakeClient) PatchWithResponse(_ rest.Request) (rest.Response, error) {
panic("not implemented")
}
func (f *fakeClient) Get(request rest.Request, dest interface{}) error {
if f.getInfoLatency != 0 {
time.Sleep(f.getInfoLatency)
}
if request.Endpoint != fmt.Sprintf("/domains/%s/dns", f.domainName) {
return fmt.Errorf("function GET for endpoint %s not implemented", request.Endpoint)
}
entries := dnsEntriesWrapper{DNSEntries: f.dnsEntries}
body, err := json.Marshal(entries)
if err != nil {
return fmt.Errorf("can't encode json: %w", err)
}
err = json.Unmarshal(body, dest)
if err != nil {
return fmt.Errorf("can't decode json: %w", err)
}
return nil
}
func (f *fakeClient) Put(request rest.Request) error {
if f.getInfoLatency != 0 {
time.Sleep(f.getInfoLatency)
}
return fmt.Errorf("function PUT for endpoint %s not implemented", request.Endpoint)
}
func (f *fakeClient) Post(request rest.Request) error {
if f.getInfoLatency != 0 {
time.Sleep(f.getInfoLatency)
}
if request.Endpoint != fmt.Sprintf("/domains/%s/dns", f.domainName) {
return fmt.Errorf("function POST for endpoint %s not implemented", request.Endpoint)
}
body, err := request.GetJSONBody()
if err != nil {
return errors.New("unable get request body")
}
var entry dnsEntryWrapper
if err := json.Unmarshal(body, &entry); err != nil {
return errors.New("unable to decode request body")
}
f.dnsEntries = append(f.dnsEntries, entry.DNSEntry)
return nil
}
func (f *fakeClient) Delete(request rest.Request) error {
if f.getInfoLatency != 0 {
time.Sleep(f.getInfoLatency)
}
if request.Endpoint != fmt.Sprintf("/domains/%s/dns", f.domainName) {
return fmt.Errorf("function DELETE for endpoint %s not implemented", request.Endpoint)
}
body, err := request.GetJSONBody()
if err != nil {
return errors.New("unable get request body")
}
var entry dnsEntryWrapper
if err := json.Unmarshal(body, &entry); err != nil {
return errors.New("unable to decode request body")
}
cp := make([]domain.DNSEntry, 0)
for _, e := range f.dnsEntries {
if e.Name == entry.DNSEntry.Name {
continue
}
cp = append(cp, e)
}
f.dnsEntries = cp
return nil
}
func (f *fakeClient) Patch(request rest.Request) error {
if f.getInfoLatency != 0 {
time.Sleep(f.getInfoLatency)
}
return fmt.Errorf("function PATCH for endpoint %s not implemented", request.Endpoint)
}

View File

@ -1,17 +1,12 @@
package transip package transip
import ( import (
"fmt"
"os" "os"
"strings"
"sync"
"testing" "testing"
"time" "time"
"github.com/go-acme/lego/v4/platform/tester" "github.com/go-acme/lego/v4/platform/tester"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/transip/gotransip/v6/domain"
) )
const envDomain = envNamespace + "DOMAIN" const envDomain = envNamespace + "DOMAIN"
@ -155,107 +150,6 @@ func TestNewDNSProviderConfig(t *testing.T) {
}) })
} }
func TestDNSProvider_concurrentGetDNSEntries(t *testing.T) {
client := &fakeClient{
getInfoLatency: 50 * time.Millisecond,
setDNSEntriesLatency: 500 * time.Millisecond,
domainName: "lego.wtf",
}
repo := domain.Repository{Client: client}
p := &DNSProvider{
config: NewDefaultConfig(),
repository: repo,
}
var wg sync.WaitGroup
wg.Add(2)
solve := func(domain1, suffix string, timeoutPresent, timeoutSolve, timeoutCleanup time.Duration) error {
time.Sleep(timeoutPresent)
err := p.Present(domain1, "", "")
if err != nil {
return err
}
time.Sleep(timeoutSolve)
var found bool
for _, entry := range client.dnsEntries {
if strings.HasSuffix(entry.Name, suffix) {
found = true
}
}
if !found {
return fmt.Errorf("record %s not found: %v", suffix, client.dnsEntries)
}
time.Sleep(timeoutCleanup)
return p.CleanUp(domain1, "", "")
}
go func() {
defer wg.Done()
err := solve("bar.lego.wtf", ".bar", 500*time.Millisecond, 100*time.Millisecond, 100*time.Millisecond)
require.NoError(t, err)
}()
go func() {
defer wg.Done()
err := solve("foo.lego.wtf", ".foo", 500*time.Millisecond, 200*time.Millisecond, 100*time.Millisecond)
require.NoError(t, err)
}()
wg.Wait()
assert.Empty(t, client.dnsEntries)
}
func TestDNSProvider_concurrentAddDNSEntry(t *testing.T) {
client := &fakeClient{
domainName: "lego.wtf",
}
repo := domain.Repository{Client: client}
p := &DNSProvider{
config: NewDefaultConfig(),
repository: repo,
}
var wg sync.WaitGroup
wg.Add(2)
solve := func(domain1 string, timeoutPresent, timeoutCleanup time.Duration) error {
time.Sleep(timeoutPresent)
err := p.Present(domain1, "", "")
if err != nil {
return err
}
time.Sleep(timeoutCleanup)
return p.CleanUp(domain1, "", "")
}
go func() {
defer wg.Done()
err := solve("bar.lego.wtf", 550*time.Millisecond, 500*time.Millisecond)
require.NoError(t, err)
}()
go func() {
defer wg.Done()
err := solve("foo.lego.wtf", 500*time.Millisecond, 100*time.Millisecond)
require.NoError(t, err)
}()
wg.Wait()
assert.Empty(t, client.dnsEntries)
}
func TestLivePresent(t *testing.T) { func TestLivePresent(t *testing.T) {
if !envTest.IsLiveTest() { if !envTest.IsLiveTest() {
t.Skip("skipping live test") t.Skip("skipping live test")