Skip to content

Commit

Permalink
wip: adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Nov 26, 2024
1 parent 3302e86 commit bd469c7
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions cli/pkg/release/providers/timoni_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package providers

import (
"testing"

"github.com/input-output-hk/catalyst-forge/lib/project/project"
"github.com/input-output-hk/catalyst-forge/lib/project/schema"
"github.com/input-output-hk/catalyst-forge/lib/tools/testutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestTimoniReleaserRelease(t *testing.T) {
newProject := func(
name string,
registries []string,
) project.Project {
return project.Project{
Name: name,
Blueprint: schema.Blueprint{
Global: schema.Global{
CI: schema.GlobalCI{
Providers: schema.Providers{
Timoni: schema.TimoniProvider{
Registries: registries,
},
},
},
},
},
}
}

tests := []struct {
name string
project project.Project
release schema.Release
config TimoniReleaserConfig
firing bool
force bool
failOn string
validate func(t *testing.T, calls []string, err error)
}{
{
name: "full",
project: newProject("test", []string{"test.com"}),
release: schema.Release{},
config: TimoniReleaserConfig{
Container: "test",
Tag: "test",
},
firing: true,
force: false,
failOn: "",
validate: func(t *testing.T, calls []string, err error) {
require.NoError(t, err)
assert.Contains(t, calls, "mod push --version test --latest=false . oci://test.com/test")
},
},
{
name: "no container",
project: newProject("test", []string{"test.com"}),
release: schema.Release{},
config: TimoniReleaserConfig{
Tag: "test",
},
firing: true,
force: false,
failOn: "",
validate: func(t *testing.T, calls []string, err error) {
require.NoError(t, err)
assert.Contains(t, calls, "mod push --version test --latest=false . oci://test.com/test-deployment")
},
},
{
name: "push fails",
project: newProject("test", []string{"test.com"}),
release: schema.Release{},
config: TimoniReleaserConfig{
Container: "test",
Tag: "test",
},
firing: true,
force: false,
failOn: "mod push",
validate: func(t *testing.T, calls []string, err error) {
require.Error(t, err)
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var calls []string
timoni := TimoniReleaser{
config: tt.config,
force: tt.force,
handler: newReleaseEventHandlerMock(tt.firing),
logger: testutils.NewNoopLogger(),
project: tt.project,
release: tt.release,
timoni: newWrappedExecuterMock(&calls, tt.failOn),
}

err := timoni.Release()

tt.validate(t, calls, err)
})
}
}

0 comments on commit bd469c7

Please sign in to comment.