Skip to content

Commit

Permalink
fixed test after refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nbys committed Feb 6, 2022
1 parent 180de74 commit e5704b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
3 changes: 1 addition & 2 deletions app/acme/dns_challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ type DNSChallenge struct {
order *acme.Order
challenges []*acme.Challenge
records []dnsprovider.Record
timeout time.Duration
pollingInterval time.Duration
}

Expand Down Expand Up @@ -388,7 +387,7 @@ func (d *DNSChallenge) waitDNSPropagation(ctx context.Context) []error {
}

func (d *DNSChallenge) checkWithNS(ctx context.Context) error {
ticker := time.NewTicker(10 * time.Second)
ticker := time.NewTicker(d.pollingInterval)

for _, record := range d.records {
var lastErr error
Expand Down
14 changes: 8 additions & 6 deletions app/acme/dns_challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func TestMain(m *testing.M) {
setupMock()
acmeV2Enpoint = mockACMEServer.URL
provider = &mockDNSProvider{}
//acmeOpTimeout = 10 * time.Second
}
os.Exit(m.Run())
}
Expand Down Expand Up @@ -600,8 +599,9 @@ func TestDNSChallenge_solveDNSChallenge(t *testing.T) {

for _, tt := range tests {
d := &DNSChallenge{
provider: &mockDNSProvider{},
domains: tt.args.domains,
provider: &mockDNSProvider{},
domains: tt.args.domains,
pollingInterval: time.Second * 10,
}

if err := d.register(); err != nil {
Expand Down Expand Up @@ -1008,7 +1008,8 @@ func TestDNSChallenge_checkWithNS(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &DNSChallenge{
nameservers: tt.fields.nameservers,
nameservers: tt.fields.nameservers,
pollingInterval: time.Second * 10,
}
ctx, cancel := context.WithTimeout(context.Background(), timeoutForTests)
d.records = tt.args.records
Expand Down Expand Up @@ -1104,8 +1105,9 @@ func TestDNSChallenge_presentRecords(t *testing.T) {
removedRecords = make([]dnsprovider.Record, 0)

d := &DNSChallenge{
provider: &mockDNSProvider{},
records: tt.fields.records,
provider: &mockDNSProvider{},
records: tt.fields.records,
pollingInterval: time.Second * 10,
}
if err := d.presentRecords(); (err != nil) && !tt.wantErr {
t.Errorf("DNSChallenge.presentRecords() error = %v, wantErr %v", err, tt.wantErr)
Expand Down
24 changes: 7 additions & 17 deletions app/acme/dnsprovider/cloudns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,10 @@ func setupMock() {

func Test_newCloudnsProvider(t *testing.T) {
type envs struct {
authID string
subAuthID string
authPassword string
TTL string
dnsPropagationTimeout string
dnsPropagationInterval string
authID string
subAuthID string
authPassword string
TTL string
}

tests := []struct {
Expand All @@ -182,13 +180,13 @@ func Test_newCloudnsProvider(t *testing.T) {
wantErr bool
}{
{"envs for authID and subAuthID not set",
envs{"", "", "", "", "", ""},
envs{"", "", "", ""},
true},
{"env for password not set",
envs{"account", "subaccount", "", "", "", ""},
envs{"account", "subaccount", "", ""},
true},
{"with default optional parameters",
envs{"account", "subaccount", "init1234", "", "", ""},
envs{"account", "subaccount", "init1234", ""},
false},
}
for _, tt := range tests {
Expand All @@ -197,8 +195,6 @@ func Test_newCloudnsProvider(t *testing.T) {
setEnv(envSubAuthID, tt.envs.subAuthID)
setEnv(envAuthPassword, tt.envs.authPassword)
setEnv(envTTL, tt.envs.TTL)
setEnv(envDNSPropagationTimeout, tt.envs.dnsPropagationTimeout)
setEnv(envDNSPropagationCheckInteval, tt.envs.dnsPropagationInterval)

got, err := newCloudnsProvider(Opts{})
if (err != nil) && !tt.wantErr {
Expand All @@ -214,12 +210,6 @@ func Test_newCloudnsProvider(t *testing.T) {
assert.Equal(t, tt.envs.subAuthID, got.subAuthID, "subAuthID")
assert.Equal(t, tt.envs.authPassword, got.authPassword, "authPassword")

expTimeout := time.Second * time.Duration(180)
assert.Equal(t, expTimeout, got.timeout, "dnsPropagationTimeout")

expInterval := time.Second * time.Duration(10)
assert.Equal(t, expInterval, got.poolingInterval, "dnsPropagationInterval")

os.Unsetenv(envAuthID)
os.Unsetenv(envSubAuthID)
os.Unsetenv(envAuthPassword)
Expand Down
8 changes: 4 additions & 4 deletions app/acme/dnsprovider/route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ type route53 struct {
secretAccessKey string
region string
hostedZoneID string
timeout time.Duration
interval time.Duration
ttl int
client *http.Client
// timeout time.Duration
// interval time.Duration
ttl int
client *http.Client
}

func newRoute53Provider(opts Opts) (*route53, error) {
Expand Down

0 comments on commit e5704b8

Please sign in to comment.