-
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.
Merge pull request #2 from Kilemonn/make-kubernetes-test-always-run
Improve Kubernetes Provider Tests
- Loading branch information
Showing
12 changed files
with
84 additions
and
53 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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,7 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: my-kubernetes-secret | ||
type: Opaque | ||
stringData: | ||
credential-name: wow-great-secret |
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
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 |
---|---|---|
@@ -1,20 +1,38 @@ | ||
package credential_provider | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func withSecretConfig(t *testing.T, filepath string, testFunc func()) { | ||
cmd := exec.Command("kubectl", "apply", "-f", filepath) | ||
output, err := cmd.Output() | ||
if err != nil { | ||
fmt.Printf("Failed to apply kubernetes config file with path: [%s]. With output [%s]. And error: [%s].", filepath, output, err.Error()) | ||
t.FailNow() | ||
return | ||
} | ||
// Assuming the configuration was applied correctly with the provided file, I am assuming it will be delete successfully too. For now | ||
defer exec.Command("kubectl", "delete", "-f", filepath) | ||
testFunc() | ||
} | ||
|
||
func TestKubernetesProvider(t *testing.T) { | ||
t.Skip("Skipping since we cannot guarantee the local kubernetes environment is correctly setup") | ||
m := make(map[string]interface{}) | ||
m[property_namespace] = "default" | ||
m[property_secret_name] = "my-kubernetes-secret" | ||
provider, err := NewKubernetesProvider(m) | ||
assert.NoError(t, err) | ||
|
||
val, err := provider.GetCredentialWithName("my-kubernetes-secret") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, val) | ||
withSecretConfig(t, "./kubernetes-test-secret.yaml", func() { | ||
provider, err := NewKubernetesProvider(m) | ||
require.NoError(t, err) | ||
defer provider.Close() | ||
|
||
val, err := provider.GetCredentialWithName("credential-name") | ||
require.NoError(t, err) | ||
require.NotEmpty(t, val) | ||
}) | ||
} |
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
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 |
---|---|---|
|
@@ -39,6 +39,6 @@ func main() { | |
} | ||
|
||
for _, provider := range providers { | ||
provider.Provider.Shutdown() | ||
provider.Provider.Close() | ||
} | ||
} |