Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed May 18, 2024
1 parent b9d2ff8 commit b968740
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ func (c *ClientCreatorPool) GetClientCreatorWithMaxRemainingRateLimit() (githuba
func (c *ClientCreatorPool) SetRateLimitRemaining(id int, remaining int) {
c.idToRateLimitRemaning[id] = remaining
}

func (c *ClientCreatorPool) GetRateLimitRemaining(id int) int {
return c.idToRateLimitRemaning[id]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package clientcreatorpool

import (
"testing"

"github.com/palantir/go-githubapp/githubapp"
"github.com/runatlantis/atlantis/server/logging"
"github.com/runatlantis/atlantis/server/metrics"
"github.com/stretchr/testify/assert"
)

func initialize(t *testing.T) ClientCreatorPool {
configs := []ClientCreatorPoolConfig{
{
id: 564754,
config: githubapp.Config{},
},
{
id: 243643,
config: githubapp.Config{},
},
}

configs[0].config.App.IntegrationID = 564754
configs[0].config.App.PrivateKey = "key1"
configs[0].config.App.WebhookSecret = "secret1"

configs[1].config.App.IntegrationID = 243643
configs[1].config.App.PrivateKey = "key2"
configs[1].config.App.WebhookSecret = "secret2"

c := ClientCreatorPool{}
ctxLogger := logging.NewNoopCtxLogger(t)
scope, _, _ := metrics.NewLoggingScope(ctxLogger, "null")
c.Initialize(configs, scope)

Check failure on line 35 in server/neptune/temporalworker/clientcreatorpool/clientcreatorpool_test.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

Error return value of `c.Initialize` is not checked (errcheck)
return c
}

func TestInitialize(t *testing.T) {
configs := []ClientCreatorPoolConfig{
{
id: 1,
config: githubapp.Config{},
},
{
id: 2,
config: githubapp.Config{},
},
}

configs[0].config.App.IntegrationID = 1
configs[0].config.App.PrivateKey = "key1"
configs[0].config.App.WebhookSecret = "secret1"

configs[1].config.App.IntegrationID = 2
configs[1].config.App.PrivateKey = "key2"
configs[1].config.App.WebhookSecret = "secret2"

c := ClientCreatorPool{}
ctxLogger := logging.NewNoopCtxLogger(t)
scope, _, _ := metrics.NewLoggingScope(ctxLogger, "null")
err := c.Initialize(configs, scope)
assert.NoError(t, err)
}

func TestGetClientCreatorWithMaxRemainingRateLimit(t *testing.T) {
c := initialize(t)
c.SetRateLimitRemaining(564754, 9000)
clientCreator, err := c.GetClientCreatorWithMaxRemainingRateLimit()
assert.NoError(t, err)
assert.NotNil(t, clientCreator)
assert.Equal(t, 9000, c.GetRateLimitRemaining(564754))

}

Check failure on line 74 in server/neptune/temporalworker/clientcreatorpool/clientcreatorpool_test.go

View workflow job for this annotation

GitHub Actions / runner / golangci-lint

unnecessary trailing newline (whitespace)

0 comments on commit b968740

Please sign in to comment.