Commit d26dd7a1 authored by Sietse Ringers's avatar Sietse Ringers

refactor: rename testdata contents

parent 53a421fd
*.test *.test
.idea/ .idea/
testdata/storage/* testdata/tmp/*
!testdata/storage/cardemu.xml !testdata/tmp/cardemu.xml
errors_*.go errors_*.go
vendor/ vendor/
\ No newline at end of file
...@@ -44,7 +44,7 @@ func parseExistingStorage(t *testing.T) (*irmaclient.Client, *TestClientHandler) ...@@ -44,7 +44,7 @@ func parseExistingStorage(t *testing.T) (*irmaclient.Client, *TestClientHandler)
handler := &TestClientHandler{t: t, c: make(chan error)} handler := &TestClientHandler{t: t, c: make(chan error)}
path := test.FindTestdataFolder(t) path := test.FindTestdataFolder(t)
client, err := irmaclient.New( client, err := irmaclient.New(
filepath.Join(path, "storage", "test"), filepath.Join(path, "tmp", "client"),
filepath.Join(path, "irma_configuration"), filepath.Join(path, "irma_configuration"),
handler, handler,
) )
......
...@@ -364,7 +364,7 @@ func TestRevocation(t *testing.T) { ...@@ -364,7 +364,7 @@ func TestRevocation(t *testing.T) {
client, _ := parseStorage(t) client, _ := parseStorage(t)
iss := irma.NewIssuerIdentifier("irma-demo.MijnOverheid") iss := irma.NewIssuerIdentifier("irma-demo.MijnOverheid")
cred := irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.root") cred := irma.NewCredentialTypeIdentifier("irma-demo.MijnOverheid.root")
dbPath := filepath.Join(testdata, "storage", "revocation", cred.String()) dbPath := filepath.Join(testdata, "tmp", "revocation", cred.String())
keystore := client.Configuration.RevocationKeystore(iss) keystore := client.Configuration.RevocationKeystore(iss)
sk, err := client.Configuration.PrivateKey(iss) sk, err := client.Configuration.PrivateKey(iss)
require.NoError(t, err) require.NoError(t, err)
......
...@@ -59,7 +59,7 @@ func StartIrmaServer(t *testing.T, updatedIrmaConf bool) { ...@@ -59,7 +59,7 @@ func StartIrmaServer(t *testing.T, updatedIrmaConf bool) {
URL: "http://localhost:48680", URL: "http://localhost:48680",
Logger: logger, Logger: logger,
SchemesPath: filepath.Join(testdata, irmaconf), SchemesPath: filepath.Join(testdata, irmaconf),
RevocationPath: filepath.Join(testdata, "storage", "revocation"), RevocationPath: filepath.Join(testdata, "tmp", "revocation"),
}) })
require.NoError(t, err) require.NoError(t, err)
...@@ -83,7 +83,7 @@ var IrmaServerConfiguration = &requestorserver.Configuration{ ...@@ -83,7 +83,7 @@ var IrmaServerConfiguration = &requestorserver.Configuration{
Logger: logger, Logger: logger,
SchemesPath: filepath.Join(testdata, "irma_configuration"), SchemesPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"), IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
RevocationPath: filepath.Join(testdata, "storage", "revocation"), RevocationPath: filepath.Join(testdata, "tmp", "revocation"),
}, },
DisableRequestorAuthentication: true, DisableRequestorAuthentication: true,
Port: 48682, Port: 48682,
...@@ -95,7 +95,7 @@ var JwtServerConfiguration = &requestorserver.Configuration{ ...@@ -95,7 +95,7 @@ var JwtServerConfiguration = &requestorserver.Configuration{
Logger: logger, Logger: logger,
SchemesPath: filepath.Join(testdata, "irma_configuration"), SchemesPath: filepath.Join(testdata, "irma_configuration"),
IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"), IssuerPrivateKeysPath: filepath.Join(testdata, "privatekeys"),
RevocationPath: filepath.Join(testdata, "storage", "revocation"), RevocationPath: filepath.Join(testdata, "tmp", "revocation"),
}, },
Port: 48682, Port: 48682,
DisableRequestorAuthentication: false, DisableRequestorAuthentication: false,
......
...@@ -437,7 +437,7 @@ func TestDownloadSchemeManager(t *testing.T) { ...@@ -437,7 +437,7 @@ func TestDownloadSchemeManager(t *testing.T) {
require.Contains(t, client.Configuration.Issuers, irma.NewIssuerIdentifier("irma-demo.RU")) require.Contains(t, client.Configuration.Issuers, irma.NewIssuerIdentifier("irma-demo.RU"))
require.Contains(t, client.Configuration.CredentialTypes, irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard")) require.Contains(t, client.Configuration.CredentialTypes, irma.NewCredentialTypeIdentifier("irma-demo.RU.studentCard"))
basepath := filepath.Join(test.FindTestdataFolder(t), "storage", "test", "irma_configuration", "irma-demo") basepath := filepath.Join(test.FindTestdataFolder(t), "tmp", "client", "irma_configuration", "irma-demo")
exists, err := fs.PathExists(filepath.Join(basepath, "description.xml")) exists, err := fs.PathExists(filepath.Join(basepath, "description.xml"))
require.NoError(t, err) require.NoError(t, err)
require.True(t, exists) require.True(t, exists)
......
...@@ -30,7 +30,7 @@ func checkError(t *testing.T, err error) { ...@@ -30,7 +30,7 @@ func checkError(t *testing.T, err error) {
var schemeServer *http.Server var schemeServer *http.Server
var badServer *http.Server var badServer *http.Server
var badServerCount int var badServerCount int
var testStorageDir = "teststorage" var testStorageDir = "client"
func StartSchemeManagerHttpServer() { func StartSchemeManagerHttpServer() {
path := FindTestdataFolder(nil) path := FindTestdataFolder(nil)
...@@ -88,32 +88,22 @@ func FindTestdataFolder(t *testing.T) string { ...@@ -88,32 +88,22 @@ func FindTestdataFolder(t *testing.T) string {
// ClearTestStorage removes any output from previously run tests to ensure a clean state; // ClearTestStorage removes any output from previously run tests to ensure a clean state;
// some of the tests don't like it when there is existing state in storage. // some of the tests don't like it when there is existing state in storage.
func ClearTestStorage(t *testing.T) { func ClearTestStorage(t *testing.T) {
path := filepath.Join(FindTestdataFolder(t), "storage") tmp := filepath.Join(FindTestdataFolder(t), "tmp")
err := os.RemoveAll(filepath.Join(path, "test")) checkError(t, os.RemoveAll(tmp))
checkError(t, err) checkError(t, fs.EnsureDirectoryExists(tmp))
err = os.RemoveAll(filepath.Join(path, "revocation"))
checkError(t, err)
} }
func CreateTestStorage(t *testing.T) { func CreateTestStorage(t *testing.T) {
ClearTestStorage(t) ClearTestStorage(t)
path := filepath.Join(FindTestdataFolder(t), "storage") tmp := filepath.Join(FindTestdataFolder(t), "tmp")
checkError(t, fs.EnsureDirectoryExists(filepath.Join(tmp, "client")))
// EnsureDirectoryExists eventually uses mkdir from the OS which is not recursive checkError(t, fs.EnsureDirectoryExists(filepath.Join(tmp, "revocation")))
// so we have to create the temporary test storage by multiple function calls.
// We ignore any error possibly returned by creating the first one, because if it errors,
// then the second one certainly will as well.
_ = fs.EnsureDirectoryExists(path)
err := fs.EnsureDirectoryExists(filepath.Join(path, "test"))
checkError(t, err)
err = fs.EnsureDirectoryExists(filepath.Join(path, "revocation"))
checkError(t, err)
} }
func SetupTestStorage(t *testing.T) { func SetupTestStorage(t *testing.T) {
CreateTestStorage(t) CreateTestStorage(t)
path := FindTestdataFolder(t) path := FindTestdataFolder(t)
err := fs.CopyDirectory(filepath.Join(path, testStorageDir), filepath.Join(path, "storage", "test")) err := fs.CopyDirectory(filepath.Join(path, testStorageDir), filepath.Join(path, "tmp", "client"))
checkError(t, err) checkError(t, err)
} }
......
package irmaclient package irmaclient
import ( import (
"github.com/privacybydesign/irmago/internal/test"
"testing" "testing"
"github.com/privacybydesign/irmago/internal/test"
) )
func TestConvertingLegacyStorage(t *testing.T) { func TestConvertingLegacyStorage(t *testing.T) {
test.SetTestStorageDir("legacy_teststorage") test.SetTestStorageDir("client_legacy")
defer test.SetTestStorageDir("teststorage") defer test.SetTestStorageDir("client")
// Test all tests in this file with legacy storage too // Test all tests in this file with legacy storage too
t.Run("TestVerify", TestVerify) t.Run("TestVerify", TestVerify)
......
...@@ -36,7 +36,7 @@ func parseStorage(t *testing.T) *Client { ...@@ -36,7 +36,7 @@ func parseStorage(t *testing.T) *Client {
func parseExistingStorage(t *testing.T) *Client { func parseExistingStorage(t *testing.T) *Client {
client, err := New( client, err := New(
filepath.Join("..", "testdata", "storage", "test"), filepath.Join("..", "testdata", "tmp", "client"),
filepath.Join("..", "testdata", "irma_configuration"), filepath.Join("..", "testdata", "irma_configuration"),
&TestClientHandler{t: t}, &TestClientHandler{t: t},
) )
...@@ -273,7 +273,7 @@ func TestWrongSchemeManager(t *testing.T) { ...@@ -273,7 +273,7 @@ func TestWrongSchemeManager(t *testing.T) {
irmademo := irma.NewSchemeManagerIdentifier("irma-demo") irmademo := irma.NewSchemeManagerIdentifier("irma-demo")
require.Contains(t, client.Configuration.SchemeManagers, irmademo) require.Contains(t, client.Configuration.SchemeManagers, irmademo)
require.NoError(t, os.Remove(filepath.Join("..", "testdata", "storage", "test", "irma_configuration", "irma-demo", "index"))) require.NoError(t, os.Remove(filepath.Join("..", "testdata", "tmp", "client", "irma_configuration", "irma-demo", "index")))
err := client.Configuration.ParseFolder() err := client.Configuration.ParseFolder()
_, ok := err.(*irma.SchemeManagerError) _, ok := err.(*irma.SchemeManagerError)
...@@ -299,7 +299,7 @@ func TestCredentialInfoListNewAttribute(t *testing.T) { ...@@ -299,7 +299,7 @@ func TestCredentialInfoListNewAttribute(t *testing.T) {
require.NoError(t, client.Configuration.ParseFolder()) require.NoError(t, client.Configuration.ParseFolder())
require.NotNil(t, client.Configuration.CredentialTypes[credid].AttributeType(attrid)) require.NotNil(t, client.Configuration.CredentialTypes[credid].AttributeType(attrid))
// irma-demo.RU.studentCard.newAttribute now exists in the scheme but not in the instance in the teststorage // irma-demo.RU.studentCard.newAttribute now exists in the scheme but not in the instance in the testdata folder
for _, credinfo := range client.CredentialInfoList() { for _, credinfo := range client.CredentialInfoList() {
if credinfo.ID == "studentCard" { if credinfo.ID == "studentCard" {
require.Nil(t, credinfo.Attributes[attrid]) require.Nil(t, credinfo.Attributes[attrid])
......
...@@ -31,7 +31,7 @@ func TestConfigurationAutocopy(t *testing.T) { ...@@ -31,7 +31,7 @@ func TestConfigurationAutocopy(t *testing.T) {
test.CreateTestStorage(t) test.CreateTestStorage(t)
defer test.ClearTestStorage(t) defer test.ClearTestStorage(t)
path := filepath.Join("testdata", "storage", "test", "irma_configuration") path := filepath.Join("testdata", "tmp", "client", "irma_configuration")
require.NoError(t, fs.CopyDirectory(filepath.Join("testdata", "irma_configuration"), path)) require.NoError(t, fs.CopyDirectory(filepath.Join("testdata", "irma_configuration"), path))
conf, err := NewConfigurationFromAssets(path, filepath.Join("testdata", "irma_configuration_updated")) conf, err := NewConfigurationFromAssets(path, filepath.Join("testdata", "irma_configuration_updated"))
require.NoError(t, err) require.NoError(t, err)
...@@ -80,7 +80,7 @@ func TestInvalidIrmaConfigurationRestoreFromRemote(t *testing.T) { ...@@ -80,7 +80,7 @@ func TestInvalidIrmaConfigurationRestoreFromRemote(t *testing.T) {
test.CreateTestStorage(t) test.CreateTestStorage(t)
defer test.ClearTestStorage(t) defer test.ClearTestStorage(t)
conf, err := NewConfigurationFromAssets(filepath.Join("testdata", "storage", "test", "irma_configuration"), conf, err := NewConfigurationFromAssets(filepath.Join("testdata", "tmp", "client", "irma_configuration"),
filepath.Join("testdata", "irma_configuration_invalid")) filepath.Join("testdata", "irma_configuration_invalid"))
require.NoError(t, err) require.NoError(t, err)
...@@ -95,7 +95,7 @@ func TestInvalidIrmaConfigurationRestoreFromAssets(t *testing.T) { ...@@ -95,7 +95,7 @@ func TestInvalidIrmaConfigurationRestoreFromAssets(t *testing.T) {
test.CreateTestStorage(t) test.CreateTestStorage(t)
defer test.ClearTestStorage(t) defer test.ClearTestStorage(t)
conf, err := NewConfigurationFromAssets(filepath.Join("testdata", "storage", "test", "irma_configuration"), conf, err := NewConfigurationFromAssets(filepath.Join("testdata", "tmp", "client", "irma_configuration"),
filepath.Join("testdata", "irma_configuration_invalid")) filepath.Join("testdata", "irma_configuration_invalid"))
require.NoError(t, err) require.NoError(t, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment