Skip to content

Commit

Permalink
test: add more test case
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Oct 9, 2024
1 parent e66b1e5 commit 3eba618
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
31 changes: 12 additions & 19 deletions cmd/pkg/cli/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/go-faker/faker/v4"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/pkg/chart"
"github.com/siyul-park/uniflow/pkg/resource"
"github.com/siyul-park/uniflow/pkg/secret"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/spf13/afero"
Expand All @@ -31,9 +30,8 @@ func TestApplyCommand_Execute(t *testing.T) {
filename := "chart.json"

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Namespace: resource.DefaultNamespace,
Name: faker.Word(),
ID: uuid.Must(uuid.NewV7()),
Name: faker.Word(),
}

data, err := json.Marshal(chrt)
Expand Down Expand Up @@ -75,9 +73,8 @@ func TestApplyCommand_Execute(t *testing.T) {
filename := "chart.json"

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Namespace: resource.DefaultNamespace,
Name: faker.Word(),
ID: uuid.Must(uuid.NewV7()),
Name: faker.Word(),
}

_, err := chartStore.Store(ctx, chrt)
Expand Down Expand Up @@ -124,9 +121,8 @@ func TestApplyCommand_Execute(t *testing.T) {
kind := faker.UUIDHyphenated()

meta := &spec.Meta{
Kind: kind,
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Kind: kind,
Name: faker.UUIDHyphenated(),
}

data, err := json.Marshal(meta)
Expand Down Expand Up @@ -170,9 +166,8 @@ func TestApplyCommand_Execute(t *testing.T) {
kind := faker.UUIDHyphenated()

meta := &spec.Meta{
Kind: kind,
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Kind: kind,
Name: faker.UUIDHyphenated(),
}

_, err := specStore.Store(ctx, meta)
Expand Down Expand Up @@ -217,9 +212,8 @@ func TestApplyCommand_Execute(t *testing.T) {
filename := "secrets.json"

scrt := &secret.Secret{
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
}

data, err := json.Marshal(scrt)
Expand Down Expand Up @@ -261,9 +255,8 @@ func TestApplyCommand_Execute(t *testing.T) {
filename := "secrets.json"

scrt := &secret.Secret{
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
}

_, err := secretStore.Store(ctx, scrt)
Expand Down
16 changes: 6 additions & 10 deletions cmd/pkg/cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/go-faker/faker/v4"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/pkg/chart"
"github.com/siyul-park/uniflow/pkg/resource"
"github.com/siyul-park/uniflow/pkg/secret"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/spf13/afero"
Expand All @@ -30,9 +29,8 @@ func TestDeleteCommand_Execute(t *testing.T) {
filename := "chart.json"

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Namespace: resource.DefaultNamespace,
Name: faker.Word(),
ID: uuid.Must(uuid.NewV7()),
Name: faker.Word(),
}

data, err := json.Marshal(chrt)
Expand Down Expand Up @@ -74,9 +72,8 @@ func TestDeleteCommand_Execute(t *testing.T) {
kind := faker.UUIDHyphenated()

meta := &spec.Meta{
Kind: kind,
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Kind: kind,
Name: faker.UUIDHyphenated(),
}

data, err := json.Marshal(meta)
Expand Down Expand Up @@ -116,9 +113,8 @@ func TestDeleteCommand_Execute(t *testing.T) {
filename := "secrets.json"

scrt := &secret.Secret{
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
}

data, err := json.Marshal(scrt)
Expand Down
16 changes: 6 additions & 10 deletions cmd/pkg/cli/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/go-faker/faker/v4"
"github.com/gofrs/uuid"
"github.com/siyul-park/uniflow/pkg/chart"
"github.com/siyul-park/uniflow/pkg/resource"
"github.com/siyul-park/uniflow/pkg/secret"
"github.com/siyul-park/uniflow/pkg/spec"
"github.com/stretchr/testify/assert"
Expand All @@ -24,9 +23,8 @@ func TestGetCommand_Execute(t *testing.T) {
defer cancel()

chrt := &chart.Chart{
ID: uuid.Must(uuid.NewV7()),
Namespace: resource.DefaultNamespace,
Name: faker.Word(),
ID: uuid.Must(uuid.NewV7()),
Name: faker.Word(),
}

_, err := chartStore.Store(ctx, chrt)
Expand Down Expand Up @@ -56,9 +54,8 @@ func TestGetCommand_Execute(t *testing.T) {
kind := faker.UUIDHyphenated()

meta := &spec.Meta{
Kind: kind,
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Kind: kind,
Name: faker.UUIDHyphenated(),
}

_, err := specStore.Store(ctx, meta)
Expand Down Expand Up @@ -86,9 +83,8 @@ func TestGetCommand_Execute(t *testing.T) {
defer cancel()

scrt := &secret.Secret{
Namespace: resource.DefaultNamespace,
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
Name: faker.UUIDHyphenated(),
Data: faker.Word(),
}

_, err := secretStore.Store(ctx, scrt)
Expand Down
38 changes: 38 additions & 0 deletions cmd/pkg/cli/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -40,6 +41,43 @@ func TestStartCommand_Execute(t *testing.T) {
s.AddKnownType(kind, &spec.Meta{})
s.AddCodec(kind, codec)

t.Run(flagDebug, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

output := new(bytes.Buffer)

cmd := NewStartCommand(StartConfig{
Scheme: s,
Hook: h,
FS: fs,
ChartStore: chartStore,
SpecStore: specStore,
SecretStore: secretStore,
})
cmd.SetOut(output)
cmd.SetErr(output)
cmd.SetContext(ctx)

cmd.SetArgs([]string{fmt.Sprintf("--%s", flagDebug)})

go func() {
_ = cmd.Execute()
}()

for {
select {
case <-ctx.Done():
assert.Fail(t, ctx.Err().Error())
return
default:
if strings.Contains(output.String(), "debug") {
return
}
}
}
})

t.Run(flagFromCharts, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
Expand Down
2 changes: 1 addition & 1 deletion pkg/chart/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (l *Loader) Load(ctx context.Context, charts ...*Chart) error {
}
if !ok {
if _, err := l.table.Free(id); err != nil {
return err
errs = append(errs, err)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/symbol/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (l *Loader) Load(ctx context.Context, specs ...spec.Spec) error {
}
if !ok {
if _, err := l.table.Free(id); err != nil {
return err
errs = append(errs, err)
}
}
}
Expand Down

0 comments on commit 3eba618

Please sign in to comment.