From 89da3c94cb97813d2a51745423e6a31a3cf99e26 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 13:44:27 +0100 Subject: [PATCH 01/12] Add test for ffconfig main Signed-off-by: Enrique Lacal --- codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/codecov.yml b/codecov.yml index 02e77f8af..2d9e329ef 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,3 +8,4 @@ coverage: threshold: 0.1% ignore: - "mocks/**/*.go" + - "ffconfig/**/*.go" From 0a026e4b2ac047c0ee32649bb33d566dd71c9c35 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 14:13:41 +0100 Subject: [PATCH 02/12] Add main test for ffconfig Signed-off-by: Enrique Lacal --- codecov.yml | 1 - ffconfig/main_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 ffconfig/main_test.go diff --git a/codecov.yml b/codecov.yml index 2d9e329ef..02e77f8af 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,4 +8,3 @@ coverage: threshold: 0.1% ignore: - "mocks/**/*.go" - - "ffconfig/**/*.go" diff --git a/ffconfig/main_test.go b/ffconfig/main_test.go new file mode 100644 index 000000000..8aa20d616 --- /dev/null +++ b/ffconfig/main_test.go @@ -0,0 +1,69 @@ +// Copyright © 2022 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +var configPath string = "../test/data/config/firefly.core.yaml" + +func TestConfigMigrateRootCmdErrorNoArgs(t *testing.T) { + rootCmd.SetArgs([]string{}) + defer rootCmd.SetArgs([]string{}) + err := rootCmd.Execute() + assert.Error(t, err) + assert.Regexp(t, "a command is required", err) +} + +func TestConfigMigrateCmdMissingConfig(t *testing.T) { + rootCmd.SetArgs([]string{"migrate"}) + defer rootCmd.SetArgs([]string{}) + err := rootCmd.Execute() + assert.Error(t, err) + assert.Regexp(t, "no such file or directory", err) +} + +func TestConfigMigrateCmd(t *testing.T) { + rootCmd.SetArgs([]string{"migrate", "-f", configPath}) + defer rootCmd.SetArgs([]string{}) + err := rootCmd.Execute() + assert.NoError(t, err) +} + +func TestConfigMigrateCmdWriteOutput(t *testing.T) { + tmpDir, err := os.MkdirTemp(os.TempDir(), "out") + assert.NoError(t, err) + defer os.RemoveAll(tmpDir) + + rootCmd.SetArgs([]string{"migrate", "-f", configPath, "-o", fmt.Sprintf(tmpDir, "out.config")}) + defer rootCmd.SetArgs([]string{}) + err = rootCmd.Execute() + assert.NoError(t, err) +} + +func TestConfigMigrateCmdBadVersion(t *testing.T) { + rootCmd.SetArgs([]string{"migrate", "-f", configPath, "--from", "badversion"}) + defer rootCmd.SetArgs([]string{}) + err := rootCmd.Execute() + assert.Error(t, err) + assert.Regexp(t, "bad 'from' version", err) +} From 447a01040a90dfd5ae958cdce1e38e1ad17b12d3 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 14:31:24 +0100 Subject: [PATCH 03/12] more test for factories Signed-off-by: Enrique Lacal --- internal/blockchain/bifactory/factory_test.go | 38 +++++++++++++++++++ .../dataexchange/dxfactory/factory_test.go | 38 +++++++++++++++++++ internal/identity/iifactory/factory_test.go | 38 +++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 internal/blockchain/bifactory/factory_test.go create mode 100644 internal/dataexchange/dxfactory/factory_test.go create mode 100644 internal/identity/iifactory/factory_test.go diff --git a/internal/blockchain/bifactory/factory_test.go b/internal/blockchain/bifactory/factory_test.go new file mode 100644 index 000000000..927e36d50 --- /dev/null +++ b/internal/blockchain/bifactory/factory_test.go @@ -0,0 +1,38 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bifactory + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10110", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "ethereum") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} diff --git a/internal/dataexchange/dxfactory/factory_test.go b/internal/dataexchange/dxfactory/factory_test.go new file mode 100644 index 000000000..7fca265d2 --- /dev/null +++ b/internal/dataexchange/dxfactory/factory_test.go @@ -0,0 +1,38 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dxfactory + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10213", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "ffdx") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} diff --git a/internal/identity/iifactory/factory_test.go b/internal/identity/iifactory/factory_test.go new file mode 100644 index 000000000..4f2cac10b --- /dev/null +++ b/internal/identity/iifactory/factory_test.go @@ -0,0 +1,38 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package iifactory + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10212", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "onchain") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} From 11667474a3daa9b4150877f7f0277f3690a84a10 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 14:34:17 +0100 Subject: [PATCH 04/12] more factories test Signed-off-by: Enrique Lacal --- internal/database/difactory/factory_test.go | 38 +++++++++++++++++++++ internal/events/eifactory/factory_test.go | 38 +++++++++++++++++++++ internal/tokens/tifactory/factory_test.go | 38 +++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 internal/database/difactory/factory_test.go create mode 100644 internal/events/eifactory/factory_test.go create mode 100644 internal/tokens/tifactory/factory_test.go diff --git a/internal/database/difactory/factory_test.go b/internal/database/difactory/factory_test.go new file mode 100644 index 000000000..505414fde --- /dev/null +++ b/internal/database/difactory/factory_test.go @@ -0,0 +1,38 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package difactory + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10122", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "postgres") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} diff --git a/internal/events/eifactory/factory_test.go b/internal/events/eifactory/factory_test.go new file mode 100644 index 000000000..fb5b7d219 --- /dev/null +++ b/internal/events/eifactory/factory_test.go @@ -0,0 +1,38 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package eifactory + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10172", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "websockets") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} diff --git a/internal/tokens/tifactory/factory_test.go b/internal/tokens/tifactory/factory_test.go new file mode 100644 index 000000000..96085907e --- /dev/null +++ b/internal/tokens/tifactory/factory_test.go @@ -0,0 +1,38 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tifactory + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10272", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "fftokens") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} From 9bb994587cab0a1271df82f2aa75ff69b73a87ae Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 14:49:47 +0100 Subject: [PATCH 05/12] Add config test factories Signed-off-by: Enrique Lacal --- internal/blockchain/bifactory/factory_test.go | 24 ++++++++++++++++++- internal/database/difactory/factory_test.go | 8 +++++++ .../dataexchange/dxfactory/factory_test.go | 8 +++++++ internal/events/eifactory/factory_test.go | 23 +++++++++++++++++- internal/identity/iifactory/factory_test.go | 8 +++++++ internal/tokens/tifactory/factory_test.go | 8 +++++++ 6 files changed, 77 insertions(+), 2 deletions(-) diff --git a/internal/blockchain/bifactory/factory_test.go b/internal/blockchain/bifactory/factory_test.go index 927e36d50..a2b493c79 100644 --- a/internal/blockchain/bifactory/factory_test.go +++ b/internal/blockchain/bifactory/factory_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/hyperledger/firefly-common/pkg/config" "github.com/stretchr/testify/assert" ) @@ -30,9 +31,30 @@ func TestGetPluginUnknown(t *testing.T) { assert.Regexp(t, "FF10110", err) } -func TestGetPlugin(t *testing.T) { +func TestGetPluginEthereum(t *testing.T) { ctx := context.Background() plugin, err := GetPlugin(ctx, "ethereum") assert.NoError(t, err) assert.NotNil(t, plugin) } + +func TestGetPluginFabric(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "fabric") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} + +func TestGetPluginTezos(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "tezos") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} + +var root = config.RootSection("di") + +func TestInitConfig(t *testing.T) { + conf := root.SubArray("plugins") + InitConfig(conf) +} diff --git a/internal/database/difactory/factory_test.go b/internal/database/difactory/factory_test.go index 505414fde..116a35c05 100644 --- a/internal/database/difactory/factory_test.go +++ b/internal/database/difactory/factory_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/hyperledger/firefly-common/pkg/config" "github.com/stretchr/testify/assert" ) @@ -36,3 +37,10 @@ func TestGetPlugin(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, plugin) } + +var root = config.RootSection("di") + +func TestInitConfig(t *testing.T) { + conf := root.SubArray("plugins") + InitConfig(conf) +} diff --git a/internal/dataexchange/dxfactory/factory_test.go b/internal/dataexchange/dxfactory/factory_test.go index 7fca265d2..989570a10 100644 --- a/internal/dataexchange/dxfactory/factory_test.go +++ b/internal/dataexchange/dxfactory/factory_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/hyperledger/firefly-common/pkg/config" "github.com/stretchr/testify/assert" ) @@ -36,3 +37,10 @@ func TestGetPlugin(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, plugin) } + +var root = config.RootSection("di") + +func TestInitConfig(t *testing.T) { + conf := root.SubArray("plugins") + InitConfig(conf) +} diff --git a/internal/events/eifactory/factory_test.go b/internal/events/eifactory/factory_test.go index fb5b7d219..fb964793e 100644 --- a/internal/events/eifactory/factory_test.go +++ b/internal/events/eifactory/factory_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/hyperledger/firefly-common/pkg/config" "github.com/stretchr/testify/assert" ) @@ -30,9 +31,29 @@ func TestGetPluginUnknown(t *testing.T) { assert.Regexp(t, "FF10172", err) } -func TestGetPlugin(t *testing.T) { +func TestGetPluginWebSockets(t *testing.T) { ctx := context.Background() plugin, err := GetPlugin(ctx, "websockets") assert.NoError(t, err) assert.NotNil(t, plugin) } + +func TestGetPluginWebHooks(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "webhooks") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} + +func TestGetPluginEvents(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "system") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} + +var root = config.RootSection("di") + +func TestInitConfig(t *testing.T) { + InitConfig(root) +} diff --git a/internal/identity/iifactory/factory_test.go b/internal/identity/iifactory/factory_test.go index 4f2cac10b..3110dbb65 100644 --- a/internal/identity/iifactory/factory_test.go +++ b/internal/identity/iifactory/factory_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/hyperledger/firefly-common/pkg/config" "github.com/stretchr/testify/assert" ) @@ -36,3 +37,10 @@ func TestGetPlugin(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, plugin) } + +var root = config.RootSection("di") + +func TestInitConfig(t *testing.T) { + conf := root.SubArray("plugins") + InitConfig(conf) +} diff --git a/internal/tokens/tifactory/factory_test.go b/internal/tokens/tifactory/factory_test.go index 96085907e..f1d122932 100644 --- a/internal/tokens/tifactory/factory_test.go +++ b/internal/tokens/tifactory/factory_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/hyperledger/firefly-common/pkg/config" "github.com/stretchr/testify/assert" ) @@ -36,3 +37,10 @@ func TestGetPlugin(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, plugin) } + +var root = config.RootSection("tokens") + +func TestInitConfig(t *testing.T) { + conf := root.SubArray("plugins") + InitConfig(conf) +} From 6bd9430f757f9e02d915ff132ef3138d0683eb65 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 14:52:09 +0100 Subject: [PATCH 06/12] missed another factory Signed-off-by: Enrique Lacal --- .../sharedstorage/ssfactory/factory_test.go | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 internal/sharedstorage/ssfactory/factory_test.go diff --git a/internal/sharedstorage/ssfactory/factory_test.go b/internal/sharedstorage/ssfactory/factory_test.go new file mode 100644 index 000000000..5013d4cf4 --- /dev/null +++ b/internal/sharedstorage/ssfactory/factory_test.go @@ -0,0 +1,46 @@ +// Copyright © 2023 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package ssfactory + +import ( + "context" + "testing" + + "github.com/hyperledger/firefly-common/pkg/config" + "github.com/stretchr/testify/assert" +) + +func TestGetPluginUnknown(t *testing.T) { + ctx := context.Background() + _, err := GetPlugin(ctx, "foo") + assert.Error(t, err) + assert.Regexp(t, "FF10134", err) +} + +func TestGetPlugin(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "ipfs") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} + +var root = config.RootSection("di") + +func TestInitConfig(t *testing.T) { + conf := root.SubArray("plugins") + InitConfig(conf) +} From b46f5186b5723c8bbc3a485d15d782c98b9380e3 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 14:53:39 +0100 Subject: [PATCH 07/12] more missed factories Signed-off-by: Enrique Lacal --- internal/database/difactory/factory_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/database/difactory/factory_test.go b/internal/database/difactory/factory_test.go index 116a35c05..f334df087 100644 --- a/internal/database/difactory/factory_test.go +++ b/internal/database/difactory/factory_test.go @@ -31,13 +31,20 @@ func TestGetPluginUnknown(t *testing.T) { assert.Regexp(t, "FF10122", err) } -func TestGetPlugin(t *testing.T) { +func TestGetPluginPostgres(t *testing.T) { ctx := context.Background() plugin, err := GetPlugin(ctx, "postgres") assert.NoError(t, err) assert.NotNil(t, plugin) } +func TestGetPluginSQLite(t *testing.T) { + ctx := context.Background() + plugin, err := GetPlugin(ctx, "sqlite3") + assert.NoError(t, err) + assert.NotNil(t, plugin) +} + var root = config.RootSection("di") func TestInitConfig(t *testing.T) { From 907a06114f56ce8a4a83d28dd60aaa604e0a4ce1 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 15:18:56 +0100 Subject: [PATCH 08/12] add test for main ffconfig Signed-off-by: Enrique Lacal --- ffconfig/main_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ffconfig/main_test.go b/ffconfig/main_test.go index 8aa20d616..31c4c4ba2 100644 --- a/ffconfig/main_test.go +++ b/ffconfig/main_test.go @@ -19,6 +19,7 @@ package main import ( "fmt" "os" + "os/exec" "testing" "github.com/stretchr/testify/assert" @@ -26,6 +27,24 @@ import ( var configPath string = "../test/data/config/firefly.core.yaml" +func TestMainFail(t *testing.T) { + // Run the crashing code when FLAG is set + if os.Getenv("FLAG") == "1" { + main() + return + } + // Run the test in a subprocess + cmd := exec.Command(os.Args[0], "-test.run=TestMainFail") + cmd.Env = append(os.Environ(), "FLAG=1") + err := cmd.Run() + + // Cast the error as *exec.ExitError and compare the result + e, ok := err.(*exec.ExitError) + expectedErrorString := "exit status 1" + assert.Equal(t, true, ok) + assert.Equal(t, expectedErrorString, e.Error()) +} + func TestConfigMigrateRootCmdErrorNoArgs(t *testing.T) { rootCmd.SetArgs([]string{}) defer rootCmd.SetArgs([]string{}) From 73f92f7843728f336cacd42ad7cad72a8c205aeb Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 15:45:08 +0100 Subject: [PATCH 09/12] comment out spanish description not being used Signed-off-by: Enrique Lacal --- .../coremsgs/es/es_struct_descriptions.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/internal/coremsgs/es/es_struct_descriptions.go b/internal/coremsgs/es/es_struct_descriptions.go index cc585b666..f3008de46 100644 --- a/internal/coremsgs/es/es_struct_descriptions.go +++ b/internal/coremsgs/es/es_struct_descriptions.go @@ -16,11 +16,6 @@ package es -import ( - "github.com/hyperledger/firefly-common/pkg/i18n" - "golang.org/x/text/language" -) - //revive:disable /* @@ -42,11 +37,11 @@ MessageHeader = ffm("Message.header", "The message header") */ -var ffm = func(key, translation string) i18n.MessageKey { - return i18n.FFM(language.Spanish, key, translation) -} +// var ffm = func(key, translation string) i18n.MessageKey { +// return i18n.FFM(language.Spanish, key, translation) +// } -var ( - // MessageHeader field descriptions - MessageHeaderID = ffm("MessageHeader.id", "El UUID del mensaje. Único para cada mensaje") -) +// var ( +// // MessageHeader field descriptions +// MessageHeaderID = ffm("MessageHeader.id", "El UUID del mensaje. Único para cada mensaje") +// ) From 010b61f17b5b5c473318458ef603af71f2d5402f Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 15:49:36 +0100 Subject: [PATCH 10/12] update copyright Signed-off-by: Enrique Lacal --- internal/coremsgs/es/es_struct_descriptions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/coremsgs/es/es_struct_descriptions.go b/internal/coremsgs/es/es_struct_descriptions.go index f3008de46..b1de120db 100644 --- a/internal/coremsgs/es/es_struct_descriptions.go +++ b/internal/coremsgs/es/es_struct_descriptions.go @@ -1,4 +1,4 @@ -// Copyright © 2022 Kaleido, Inc. +// Copyright © 2024 Kaleido, Inc. // // SPDX-License-Identifier: Apache-2.0 // From e1fb4f505eaa87e6719b12f02fb8480dae643b1b Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 16:13:49 +0100 Subject: [PATCH 11/12] add test for exit ffconfig main Signed-off-by: Enrique Lacal --- ffconfig/main_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ffconfig/main_test.go b/ffconfig/main_test.go index 31c4c4ba2..f7b136561 100644 --- a/ffconfig/main_test.go +++ b/ffconfig/main_test.go @@ -68,6 +68,24 @@ func TestConfigMigrateCmd(t *testing.T) { assert.NoError(t, err) } +func TestMain(t *testing.T) { + // Run the exiting code when FLAG is set + if os.Getenv("FLAG") == "0" { + rootCmd.SetArgs([]string{"migrate", "-f", configPath}) + main() + return + } + + // Run the test in a subprocess + cmd := exec.Command(os.Args[0], "-test.run=TestMain") + cmd.Env = append(os.Environ(), "FLAG=0") + err := cmd.Run() + + // Cast the error as *exec.ExitError and compare the result + _, ok := err.(*exec.ExitError) + assert.Equal(t, false, ok) +} + func TestConfigMigrateCmdWriteOutput(t *testing.T) { tmpDir, err := os.MkdirTemp(os.TempDir(), "out") assert.NoError(t, err) From 97e016909cb49096f302cf613c5d60c840e0fd20 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Tue, 17 Sep 2024 17:19:30 +0100 Subject: [PATCH 12/12] delete spanish empty descriptions Signed-off-by: Enrique Lacal --- .../coremsgs/es/es_struct_descriptions.go | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 internal/coremsgs/es/es_struct_descriptions.go diff --git a/internal/coremsgs/es/es_struct_descriptions.go b/internal/coremsgs/es/es_struct_descriptions.go deleted file mode 100644 index b1de120db..000000000 --- a/internal/coremsgs/es/es_struct_descriptions.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright © 2024 Kaleido, Inc. -// -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package es - -//revive:disable - -/* -This file contains the field level descriptions that are used in -OpenAPI Spec generation. Each struct field that wants to use one of these -needs to have an ffstruct tag on it, indicating the name of the struct. -That will be combined with the JSON field name (note, it is not the GO -field name, but the JSON serialized name), separated by a "." This is the -key used to lookup the translation below. If it is not found, the description -is left blank in the OpenAPI spec - -Example: -// message.go -type Message struct { - Header MessageHeader `ffstruct:"Message" json:"header"` - -// en_translations_descriptions.go -MessageHeader = ffm("Message.header", "The message header") - -*/ - -// var ffm = func(key, translation string) i18n.MessageKey { -// return i18n.FFM(language.Spanish, key, translation) -// } - -// var ( -// // MessageHeader field descriptions -// MessageHeaderID = ffm("MessageHeader.id", "El UUID del mensaje. Único para cada mensaje") -// )