-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adapt tests to service factory and move them into config package
Signed-off-by: Jason Dellaluce <[email protected]>
- Loading branch information
1 parent
47ad3ad
commit b096654
Showing
2 changed files
with
83 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/FedeDP/GhEnvSet/pkg/poiana" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const testYAML = ` | ||
orgs: | ||
FedeDP: | ||
actions: | ||
variables: | ||
orgVar1: "orgValue1" | ||
secrets: | ||
- orgSecret0 | ||
repos: | ||
GhEnvSet: | ||
actions: | ||
variables: | ||
repoVar1: "repoValue1" | ||
repoVar2: "repoValue2" | ||
secrets: | ||
- repoSecret0 | ||
- repoSecret1 | ||
- repoSecret2 | ||
` | ||
|
||
func TestConfigSync(t *testing.T) { | ||
org := "FedeDP" | ||
repo := "GhEnvSet" | ||
ctx := context.Background() | ||
|
||
conf, err := FromData(testYAML) | ||
assert.NoError(t, err) | ||
|
||
factory := poiana.NewMockServiceFactory() | ||
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) | ||
assert.NoError(t, err) | ||
|
||
// Org | ||
// Check variables | ||
orgVars := factory.NewOrgVariableService(org) | ||
vars, _, err := orgVars.ListVariables(ctx, nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, vars.TotalCount, len(conf.Orgs[org].Actions.Variables)) | ||
for _, v := range vars.Variables { | ||
assert.Equal(t, conf.Orgs[org].Actions.Variables[v.Name], v.Value) | ||
} | ||
|
||
// Check secrets | ||
orgSecs := factory.NewOrgSecretService(org) | ||
secs, _, err := orgSecs.ListSecrets(ctx, nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, secs.TotalCount, len(conf.Orgs[org].Actions.Secrets)) | ||
for _, sec := range secs.Secrets { | ||
assert.Contains(t, conf.Orgs[org].Actions.Secrets, sec.Name) | ||
} | ||
|
||
// Repo | ||
// Check variables | ||
repoVars := factory.NewRepoVariableService(org, repo) | ||
vars, _, err = repoVars.ListVariables(ctx, nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, vars.TotalCount, len(conf.Orgs[org].Repos[repo].Actions.Variables)) | ||
for _, v := range vars.Variables { | ||
assert.Equal(t, conf.Orgs[org].Repos[repo].Actions.Variables[v.Name], v.Value) | ||
} | ||
|
||
// Check secrets | ||
repoSecs := factory.NewRepoSecretService(org, repo) | ||
secs, _, err = repoSecs.ListSecrets(ctx, nil) | ||
assert.NoError(t, err) | ||
assert.Equal(t, secs.TotalCount, len(conf.Orgs[org].Repos[repo].Actions.Secrets)) | ||
for _, sec := range secs.Secrets { | ||
assert.Contains(t, conf.Orgs[org].Repos[repo].Actions.Secrets, sec.Name) | ||
} | ||
} |