From c119d3c3767c4630aab3cb9c7fe9c327e793c141 Mon Sep 17 00:00:00 2001 From: Ankitsinghsisodya Date: Thu, 2 Apr 2026 00:35:40 +0530 Subject: [PATCH 1/2] test: add unit coverage for ci config accessors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add tests for CIConfig accessor methods and resolveBuilder helper in cmd/ci/config.go. Covered: - FnGitHubWorkflowFilepath correctly joins fnRoot, workflow dir and filename - OutputPath uses the default dir/filename constants - Verbose, FnRuntime, FnBuilder simple getters - resolveBuilder — all supported runtimes (go, node, typescript, rust, quarkus, springboot, python) both local and remote modes, plus error for unknown runtime - All remaining bool accessors: RegistryLogin, SelfHostedRunner, RemoteBuild, WorkflowDispatch, TestStep, Force - All string accessors: Branch, WorkflowName, KubeconfigSecret, RegistryLoginUrlVar, RegistryUserVar, RegistryPassSecret, RegistryUrlVar Fixes zero-coverage on config.go:221, 226, 282, 286, 290. --- cmd/ci/config_test.go | 130 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 cmd/ci/config_test.go diff --git a/cmd/ci/config_test.go b/cmd/ci/config_test.go new file mode 100644 index 0000000000..324c448c1e --- /dev/null +++ b/cmd/ci/config_test.go @@ -0,0 +1,130 @@ +package ci + +import ( + "path/filepath" + "testing" + + "gotest.tools/v3/assert" +) + +// --------------------------------------------------------------------------- +// Pure accessor methods on a hand-built CIConfig +// --------------------------------------------------------------------------- + +func TestCIConfig_Verbose(t *testing.T) { + assert.Assert(t, !CIConfig{verbose: false}.Verbose()) + assert.Assert(t, CIConfig{verbose: true}.Verbose()) +} + +func TestCIConfig_FnRuntime(t *testing.T) { + assert.Equal(t, CIConfig{fnRuntime: "go"}.FnRuntime(), "go") + assert.Equal(t, CIConfig{fnRuntime: "python"}.FnRuntime(), "python") +} + +func TestCIConfig_FnBuilder(t *testing.T) { + assert.Equal(t, CIConfig{fnBuilder: "host"}.FnBuilder(), "host") + assert.Equal(t, CIConfig{fnBuilder: "pack"}.FnBuilder(), "pack") + assert.Equal(t, CIConfig{fnBuilder: "s2i"}.FnBuilder(), "s2i") +} + +func TestCIConfig_OutputPath(t *testing.T) { + cc := CIConfig{ + githubWorkflowDir: DefaultGitHubWorkflowDir, + githubWorkflowFilename: DefaultGitHubWorkflowFilename, + } + want := filepath.Join(DefaultGitHubWorkflowDir, DefaultGitHubWorkflowFilename) + assert.Equal(t, cc.OutputPath(), want) +} + +func TestCIConfig_FnGitHubWorkflowFilepath(t *testing.T) { + root := "/home/user/myfunc" + cc := CIConfig{ + fnRoot: root, + githubWorkflowDir: DefaultGitHubWorkflowDir, + githubWorkflowFilename: DefaultGitHubWorkflowFilename, + } + want := filepath.Join(root, DefaultGitHubWorkflowDir, DefaultGitHubWorkflowFilename) + assert.Equal(t, cc.FnGitHubWorkflowFilepath(), want) +} + +// --------------------------------------------------------------------------- +// resolveBuilder — the main untested code block from config.go +// --------------------------------------------------------------------------- + +func TestResolveBuilder(t *testing.T) { + tests := []struct { + name string + runtime string + remote bool + want string + wantErr bool + }{ + {name: "go local", runtime: "go", remote: false, want: "host"}, + {name: "go remote", runtime: "go", remote: true, want: "pack"}, + {name: "node local", runtime: "node", remote: false, want: "pack"}, + {name: "node remote", runtime: "node", remote: true, want: "pack"}, + {name: "typescript local", runtime: "typescript", remote: false, want: "pack"}, + {name: "typescript remote", runtime: "typescript", remote: true, want: "pack"}, + {name: "rust local", runtime: "rust", remote: false, want: "pack"}, + {name: "rust remote", runtime: "rust", remote: true, want: "pack"}, + {name: "quarkus local", runtime: "quarkus", remote: false, want: "pack"}, + {name: "quarkus remote", runtime: "quarkus", remote: true, want: "pack"}, + {name: "springboot local", runtime: "springboot", remote: false, want: "pack"}, + {name: "springboot remote", runtime: "springboot", remote: true, want: "pack"}, + {name: "python local", runtime: "python", remote: false, want: "host"}, + {name: "python remote", runtime: "python", remote: true, want: "s2i"}, + {name: "unknown runtime", runtime: "fortran", remote: false, wantErr: true}, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + got, err := resolveBuilder(tc.runtime, tc.remote) + if tc.wantErr { + assert.Assert(t, err != nil, "expected an error for runtime %q", tc.runtime) + return + } + assert.NilError(t, err) + assert.Equal(t, got, tc.want) + }) + } +} + +// --------------------------------------------------------------------------- +// Additional simple bool/string accessors +// --------------------------------------------------------------------------- + +func TestCIConfig_BoolAccessors(t *testing.T) { + cc := CIConfig{ + registryLogin: true, + selfHostedRunner: true, + remoteBuild: true, + workflowDispatch: true, + testStep: true, + force: true, + } + assert.Assert(t, cc.RegistryLogin()) + assert.Assert(t, cc.SelfHostedRunner()) + assert.Assert(t, cc.RemoteBuild()) + assert.Assert(t, cc.WorkflowDispatch()) + assert.Assert(t, cc.TestStep()) + assert.Assert(t, cc.Force()) +} + +func TestCIConfig_StringAccessors(t *testing.T) { + cc := CIConfig{ + branch: "feature-x", + workflowName: "My Deploy", + kubeconfigSecret: "MY_KUBECONFIG", + registryLoginUrlVar: "MY_REGISTRY_URL", + registryUserVar: "MY_USER", + registryPassSecret: "MY_PASS", + registryUrlVar: "MY_REG", + } + assert.Equal(t, cc.Branch(), "feature-x") + assert.Equal(t, cc.WorkflowName(), "My Deploy") + assert.Equal(t, cc.KubeconfigSecret(), "MY_KUBECONFIG") + assert.Equal(t, cc.RegistryLoginUrlVar(), "MY_REGISTRY_URL") + assert.Equal(t, cc.RegistryUserVar(), "MY_USER") + assert.Equal(t, cc.RegistryPassSecret(), "MY_PASS") + assert.Equal(t, cc.RegistryUrlVar(), "MY_REG") +} From 726ed6443acbf75e4db06c181dc55cb6ff0fbac1 Mon Sep 17 00:00:00 2001 From: Ankitsinghsisodya Date: Thu, 2 Apr 2026 03:45:59 +0530 Subject: [PATCH 2/2] test: drop trivial getter tests, keep only TestResolveBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed accessor tests for one-liner getters (Verbose, FnRuntime, FnBuilder, BoolAccessors, StringAccessors, OutputPath, FnGitHubWorkflowFilepath) — they test Go's struct assignment, not any real logic. Kept TestResolveBuilder (15 sub-cases) which covers the non-trivial branching in resolveBuilder() across all runtimes × local/remote. --- cmd/ci/config_test.go | 87 +------------------------------------------ 1 file changed, 2 insertions(+), 85 deletions(-) diff --git a/cmd/ci/config_test.go b/cmd/ci/config_test.go index 324c448c1e..3694876522 100644 --- a/cmd/ci/config_test.go +++ b/cmd/ci/config_test.go @@ -1,56 +1,13 @@ package ci import ( - "path/filepath" "testing" "gotest.tools/v3/assert" ) -// --------------------------------------------------------------------------- -// Pure accessor methods on a hand-built CIConfig -// --------------------------------------------------------------------------- - -func TestCIConfig_Verbose(t *testing.T) { - assert.Assert(t, !CIConfig{verbose: false}.Verbose()) - assert.Assert(t, CIConfig{verbose: true}.Verbose()) -} - -func TestCIConfig_FnRuntime(t *testing.T) { - assert.Equal(t, CIConfig{fnRuntime: "go"}.FnRuntime(), "go") - assert.Equal(t, CIConfig{fnRuntime: "python"}.FnRuntime(), "python") -} - -func TestCIConfig_FnBuilder(t *testing.T) { - assert.Equal(t, CIConfig{fnBuilder: "host"}.FnBuilder(), "host") - assert.Equal(t, CIConfig{fnBuilder: "pack"}.FnBuilder(), "pack") - assert.Equal(t, CIConfig{fnBuilder: "s2i"}.FnBuilder(), "s2i") -} - -func TestCIConfig_OutputPath(t *testing.T) { - cc := CIConfig{ - githubWorkflowDir: DefaultGitHubWorkflowDir, - githubWorkflowFilename: DefaultGitHubWorkflowFilename, - } - want := filepath.Join(DefaultGitHubWorkflowDir, DefaultGitHubWorkflowFilename) - assert.Equal(t, cc.OutputPath(), want) -} - -func TestCIConfig_FnGitHubWorkflowFilepath(t *testing.T) { - root := "/home/user/myfunc" - cc := CIConfig{ - fnRoot: root, - githubWorkflowDir: DefaultGitHubWorkflowDir, - githubWorkflowFilename: DefaultGitHubWorkflowFilename, - } - want := filepath.Join(root, DefaultGitHubWorkflowDir, DefaultGitHubWorkflowFilename) - assert.Equal(t, cc.FnGitHubWorkflowFilepath(), want) -} - -// --------------------------------------------------------------------------- -// resolveBuilder — the main untested code block from config.go -// --------------------------------------------------------------------------- - +// TestResolveBuilder covers the branching logic that selects the correct +// build strategy for each runtime × local/remote combination. func TestResolveBuilder(t *testing.T) { tests := []struct { name string @@ -88,43 +45,3 @@ func TestResolveBuilder(t *testing.T) { }) } } - -// --------------------------------------------------------------------------- -// Additional simple bool/string accessors -// --------------------------------------------------------------------------- - -func TestCIConfig_BoolAccessors(t *testing.T) { - cc := CIConfig{ - registryLogin: true, - selfHostedRunner: true, - remoteBuild: true, - workflowDispatch: true, - testStep: true, - force: true, - } - assert.Assert(t, cc.RegistryLogin()) - assert.Assert(t, cc.SelfHostedRunner()) - assert.Assert(t, cc.RemoteBuild()) - assert.Assert(t, cc.WorkflowDispatch()) - assert.Assert(t, cc.TestStep()) - assert.Assert(t, cc.Force()) -} - -func TestCIConfig_StringAccessors(t *testing.T) { - cc := CIConfig{ - branch: "feature-x", - workflowName: "My Deploy", - kubeconfigSecret: "MY_KUBECONFIG", - registryLoginUrlVar: "MY_REGISTRY_URL", - registryUserVar: "MY_USER", - registryPassSecret: "MY_PASS", - registryUrlVar: "MY_REG", - } - assert.Equal(t, cc.Branch(), "feature-x") - assert.Equal(t, cc.WorkflowName(), "My Deploy") - assert.Equal(t, cc.KubeconfigSecret(), "MY_KUBECONFIG") - assert.Equal(t, cc.RegistryLoginUrlVar(), "MY_REGISTRY_URL") - assert.Equal(t, cc.RegistryUserVar(), "MY_USER") - assert.Equal(t, cc.RegistryPassSecret(), "MY_PASS") - assert.Equal(t, cc.RegistryUrlVar(), "MY_REG") -}