Skip to content

Commit

Permalink
chore(pkg): minor fixes found by goland.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP committed Feb 9, 2023
1 parent b096654 commit b06faa3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
21 changes: 16 additions & 5 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (

const testYAML = `
orgs:
FedeDP:
myOrg:
actions:
variables:
orgVar1: "orgValue1"
secrets:
- orgSecret0
repos:
GhEnvSet:
myRepo:
actions:
variables:
repoVar1: "repoValue1"
Expand All @@ -29,15 +29,26 @@ orgs:
`

func TestConfigSync(t *testing.T) {
org := "FedeDP"
repo := "GhEnvSet"
org := "myOrg"
repo := "myRepo"
ctx := context.Background()

conf, err := FromData(testYAML)
assert.NoError(t, err)

// Check correct yaml parsing
assert.Contains(t, conf.Orgs, org)
assert.Contains(t, conf.Orgs[org].Actions.Secrets, "orgSecret0")
assert.Contains(t, conf.Orgs[org].Actions.Variables, "orgVar1")
assert.Contains(t, conf.Orgs[org].Repos, repo)

factory := poiana.NewMockServiceFactory()
provider, err := poiana.NewMockSecretsProvider(map[string]string{"orgSecret0": "orgValue0", "repoSecret0": "repoValue0", "repoSecret1": "repoValue1", "repoSecret2": "repoValue2"})
provider, err := poiana.NewMockSecretsProvider(map[string]string{
"orgSecret0": "orgValue0",
"repoSecret0": "repoValue0",
"repoSecret1": "repoValue1",
"repoSecret2": "repoValue2",
})
assert.NoError(t, err)

err = conf.Sync(factory, provider, false)
Expand Down
8 changes: 4 additions & 4 deletions pkg/poiana/secrets_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type mockSecretsService struct {
secrets map[string]*github.EncryptedSecret
}

func (pk *mockSecretsService) GetPublicKey(ctx context.Context) (*github.PublicKey, *github.Response, error) {
func (m *mockSecretsService) GetPublicKey(ctx context.Context) (*github.PublicKey, *github.Response, error) {
keyID := "testing"
key := base64.StdEncoding.EncodeToString([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) // 32B key
pKey := github.PublicKey{
Expand All @@ -40,7 +40,7 @@ func (pk *mockSecretsService) GetPublicKey(ctx context.Context) (*github.PublicK
return &pKey, nil, nil
}

func (m mockSecretsService) ListSecrets(_ context.Context, _ *github.ListOptions) (*github.Secrets, *github.Response, error) {
func (m *mockSecretsService) ListSecrets(_ context.Context, _ *github.ListOptions) (*github.Secrets, *github.Response, error) {
secs := make([]*github.Secret, 0)
for key := range m.secrets {
secs = append(secs, &github.Secret{
Expand All @@ -54,12 +54,12 @@ func (m mockSecretsService) ListSecrets(_ context.Context, _ *github.ListOptions
}, nil, nil
}

func (m mockSecretsService) DeleteSecret(_ context.Context, name string) (*github.Response, error) {
func (m *mockSecretsService) DeleteSecret(_ context.Context, name string) (*github.Response, error) {
delete(m.secrets, name)
return nil, nil
}

func (m mockSecretsService) CreateOrUpdateSecret(_ context.Context, eSecret *github.EncryptedSecret) (*github.Response, error) {
func (m *mockSecretsService) CreateOrUpdateSecret(_ context.Context, eSecret *github.EncryptedSecret) (*github.Response, error) {
m.secrets[eSecret.Name] = eSecret
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/poiana/service_factory_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type clientServiceFactory struct {
client *github.Client
}

func NewClientServiceFactory(client *github.Client) *clientServiceFactory {
func NewClientServiceFactory(client *github.Client) ServiceFactory {
return &clientServiceFactory{client: client}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/poiana/service_factory_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type mockServiceFactory struct {
vars map[string]ActionsVarsService
}

func NewMockServiceFactory() mockServiceFactory {
func NewMockServiceFactory() ServiceFactory {
return mockServiceFactory{
secs: make(map[string]ActionsSecretsService),
vars: make(map[string]ActionsVarsService),
Expand Down

0 comments on commit b06faa3

Please sign in to comment.