1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-16 05:16:08 +02:00
sap-jenkins-library/pkg/java/keytool_test.go
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

69 lines
2.1 KiB
Go

//go:build unit
// +build unit
package java
import (
"os"
"path/filepath"
"strings"
"testing"
piperMock "github.com/SAP/jenkins-library/pkg/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestGetDefaultTruststorePath(t *testing.T) {
// prepare
os.Setenv("JAVA_HOME", mock.Anything)
require.Equal(t, mock.Anything, os.Getenv("JAVA_HOME"))
// test
result := GetDefaultTruststorePath()
// assert
assert.Equal(t, "lib/security/cacerts", defaultTruststorePath)
assert.Equal(t, filepath.Join(mock.Anything, defaultTruststorePath), result)
// restore
os.Unsetenv("JAVA_HOME")
}
func TestGetMavenOpts(t *testing.T) {
// test
result := GetMavenOpts(mock.Anything)
// assert
assert.Equal(t, "changeit", DefaultTruststorePassword)
assert.Equal(t, "-Djavax.net.ssl.trustStore="+mock.Anything+" -Djavax.net.ssl.trustStorePassword="+DefaultTruststorePassword, result)
}
func TestImportCert(t *testing.T) {
// prepare
secretstorePath := filepath.Join(mock.Anything, mock.Anything)
mockRunner := &piperMock.ExecMockRunner{}
// test
err := ImportCert(mockRunner, mock.Anything, secretstorePath)
// assert
assert.NoError(t, err)
assert.Len(t, mockRunner.Calls, 1)
for _, call := range mockRunner.Calls {
assert.Equal(t, "keytool", call.Exec)
assert.Equal(t, strings.Join(call.Params, " "), "-import -noprompt -storepass changeit -keystore mock.Anything -file "+secretstorePath+" -alias mock.Anything")
}
}
func TestImportTruststore(t *testing.T) {
// prepare
srcSecretstorePath := filepath.Join(mock.Anything, mock.Anything)
destSecretstorePath := filepath.Join(mock.Anything, mock.Anything)
mockRunner := &piperMock.ExecMockRunner{}
// test
err := ImportTruststore(mockRunner, destSecretstorePath, srcSecretstorePath)
// assert
assert.NoError(t, err)
assert.Len(t, mockRunner.Calls, 1)
for _, call := range mockRunner.Calls {
assert.Equal(t, "keytool", call.Exec)
assert.Equal(t, strings.Join(call.Params, " "), "-importkeystore -noprompt -srckeystore "+srcSecretstorePath+" -srcstorepass changeit -destkeystore "+destSecretstorePath+" -deststorepass changeit")
}
}