Skip to content

Commit

Permalink
Merge branch 'main' into CLC-219
Browse files Browse the repository at this point in the history
# Conflicts:
#	clc/paths/paths.go
  • Loading branch information
kutluhanmetin committed Aug 29, 2023
2 parents f3fe29f + a4a16f6 commit 286456a
Show file tree
Hide file tree
Showing 80 changed files with 1,702 additions and 421 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/jira.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ jobs:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
TARGET_JIRA_PROJECT: API
JIRA_LABEL: CLC
TARGET_JIRA_PROJECT: CLC
ISSUE_TYPE: Bug
5 changes: 0 additions & 5 deletions .github/workflows/nightly_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,4 @@ jobs:
- name: "Run All Tests"
run: |
make test
- name: "Run Coverage"
run: |
make test-cover
make view-cover
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ IS_CHECK_VERSION ?= enabled
LDFLAGS = "-s -w -X 'github.com/hazelcast/hazelcast-commandline-client/internal.GitCommit=$(GIT_COMMIT)' -X 'github.com/hazelcast/hazelcast-commandline-client/internal.Version=$(CLC_VERSION)' -X 'github.com/hazelcast/hazelcast-go-client/internal.ClientType=CLC' -X 'github.com/hazelcast/hazelcast-go-client/internal.ClientVersion=$(CLC_VERSION)' -X 'github.com/hazelcast/hazelcast-commandline-client/internal.IsCheckVersion=$(ENABLE_CHECK_VERSION)'"
MAIN_CMD_HELP ?= Hazelcast CLC
LDFLAGS = -s -w -X 'github.com/hazelcast/hazelcast-commandline-client/clc/cmd.MainCommandShortHelp=$(MAIN_CMD_HELP)' -X 'github.com/hazelcast/hazelcast-commandline-client/internal.GitCommit=$(GIT_COMMIT)' -X 'github.com/hazelcast/hazelcast-commandline-client/internal.Version=$(CLC_VERSION)' -X 'github.com/hazelcast/hazelcast-go-client/internal.ClientType=CLC' -X 'github.com/hazelcast/hazelcast-go-client/internal.ClientVersion=$(CLC_VERSION)'
TEST_FLAGS ?= -v -count 1 -timeout 30m -race
TEST_FLAGS ?= -count 1 -timeout 30m -race
COVERAGE_OUT = coverage.out
PACKAGES = $(shell go list ./... | grep -v internal/it | tr '\n' ',')
BINARY_NAME ?= clc
Expand Down
6 changes: 6 additions & 0 deletions base/commands/config/config_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func (cm AddCmd) Exec(_ context.Context, ec plug.ExecContext) error {
if ec.Interactive() || ec.Props().GetBool(clc.PropertyVerbose) {
I2(fmt.Fprintf(ec.Stdout(), "Created configuration at: %s\n", filepath.Join(dir, cfgPath)))
}
mopt := config.ConvertKeyValuesToMap(opts)
// ignoring the JSON path for now
_, _, err = config.CreateJSON(target, mopt)
if err != nil {
ec.Logger().Warn("Failed creating the JSON configuration: %s", err.Error())
}
return nil
}

Expand Down
12 changes: 4 additions & 8 deletions base/commands/config/config_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,16 @@ func (cm ImportCmd) Init(cc plug.InitContext) error {
short := "Imports configuration from an arbitrary source"
long := `Imports configuration from an arbitrary source
Currently importing only Viridian connection configuration is supported.
Currently importing Viridian connection configuration is supported only.
1. On Viridian console, visit:
Dashboard -> Connect Client -> Quick connection guide -> Python
Dashboard -> Connect Client -> CLI
2. Copy the text in box 1 and pass it as the second parameter.
2. Copy the URL in box 2 and pass it as the second parameter.
Make sure the text is quoted before running:
clc config import my-config "curl https://api.viridian.hazelcast.com ... default.zip"
Alternatively, you can use an already downloaded Python client sample:
clc config import my-config /home/me/Downloads/hazelcast-cloud-python-sample....zip
clc config import my-config "https://api.viridian.hazelcast.com/client_samples/download/..."
`
cc.SetCommandHelp(long, short)
Expand Down
2 changes: 1 addition & 1 deletion base/commands/config/config_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestConfig(t *testing.T) {

func importTest(t *testing.T) {
tcx := it.TestContext{T: t}
const configURL = "https://rcd-download.s3.us-east-2.amazonaws.com/hazelcast-cloud-python-sample-client-pr-FOR_TESTING-default.zip"
const configURL = "https://rcd-download.s3.us-east-2.amazonaws.com/hazelcast-cloud-clc-sample-client-pr-FOR_TESTING-default.zip"
tcx.Tester(func(tcx it.TestContext) {
name := it.NewUniqueObjectName("cfg")
ctx := context.Background()
Expand Down
1 change: 1 addition & 0 deletions base/commands/demo/demo_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestGenerateData(t *testing.T) {
}

func generateData_WikipediaTest(t *testing.T) {
it.MarkFlaky(t, "https://github.com/hazelcast/hazelcast-commandline-client/issues/350")
it.MapTester(t, func(tcx it.TestContext, m *hz.Map) {
t := tcx.T
ctx := context.Background()
Expand Down
3 changes: 3 additions & 0 deletions base/commands/demo/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package demo

// This file exists only for compilation
3 changes: 1 addition & 2 deletions base/commands/map/map_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"context"
"fmt"

"github.com/hazelcast/hazelcast-go-client"

"github.com/hazelcast/hazelcast-commandline-client/clc"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/plug"
"github.com/hazelcast/hazelcast-commandline-client/internal/proto/codec"
"github.com/hazelcast/hazelcast-go-client"
)

type MapSetCommand struct{}
Expand Down
57 changes: 3 additions & 54 deletions base/commands/object/object_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"sort"
"strings"

"github.com/hazelcast/hazelcast-go-client/types"

"github.com/hazelcast/hazelcast-commandline-client/base/objects"
"github.com/hazelcast/hazelcast-commandline-client/clc"
. "github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/output"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (cm ObjectListCommand) Exec(ctx context.Context, ec plug.ExecContext) error
typeFilter = ec.Args()[0]
}
showHidden := ec.Props().GetBool(flagShowHidden)
objs, err := getObjects(ctx, ec, typeFilter, showHidden)
objs, err := objects.GetAll(ctx, ec, typeFilter, showHidden)
if err != nil {
return err
}
Expand All @@ -100,7 +99,7 @@ func (cm ObjectListCommand) Exec(ctx context.Context, ec plug.ExecContext) error
output.Column{
Name: "Service Name",
Type: serialization.TypeString,
Value: shortType(o.ServiceName),
Value: objects.ShortType(o.ServiceName),
},
valueCol,
})
Expand All @@ -122,56 +121,6 @@ func objectFilterTypes() string {
return sb.String()
}

func getObjects(ctx context.Context, ec plug.ExecContext, typeFilter string, showHidden bool) ([]types.DistributedObjectInfo, error) {
ci, err := ec.ClientInternal(ctx)
if err != nil {
return nil, err
}
objs, stop, err := ec.ExecuteBlocking(ctx, func(ctx context.Context, sp clc.Spinner) (any, error) {
sp.SetText("Getting distributed objects")
return ci.Client().GetDistributedObjectsInfo(ctx)
})
if err != nil {
return nil, err
}
stop()
var r []types.DistributedObjectInfo
typeFilter = strings.ToLower(typeFilter)
for _, o := range objs.([]types.DistributedObjectInfo) {
if !showHidden && (o.Name == "" || strings.HasPrefix(o.Name, "__")) {
continue
}
if o.Name == "" {
o.Name = "(no name)"
}
if typeFilter == "" {
r = append(r, o)
continue
}
if typeFilter == shortType(o.ServiceName) {
r = append(r, o)
}
}
sort.Slice(r, func(i, j int) bool {
// first sort by type, then name
ri := r[i]
rj := r[j]
if ri.ServiceName < rj.ServiceName {
return true
}
if ri.ServiceName > rj.ServiceName {
return false
}
return ri.Name < rj.Name
})
return r, nil
}

func shortType(svcName string) string {
s := strings.TrimSuffix(strings.TrimPrefix(svcName, "hz:impl:"), "Service")
return strings.ToLower(s)
}

func init() {
// sort objectTypes so they look better in help
sort.Slice(objTypes, func(i, j int) bool {
Expand Down
3 changes: 2 additions & 1 deletion base/commands/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ func (gc ProjectCommand) Exec(ctx context.Context, ec plug.ExecContext) error {
}

func init() {
Must(plug.Registry.RegisterCommand("project", &ProjectCommand{}))
cmd := &ProjectCommand{}
Must(plug.Registry.RegisterCommand("project", cmd))
}
31 changes: 14 additions & 17 deletions base/commands/project/project_create_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,22 @@ import (
)

func TestCreateCommand(t *testing.T) {
// TODO: create a temp home and copy the template into it
testDir := filepath.Join(check.MustValue(filepath.Abs("testdata")))
home := filepath.Join(testDir, "home")
tcx := it.TestContext{T: t}
tcx.Tester(func(tcx it.TestContext) {
it.WithEnv(paths.EnvCLCHome, home, func() {
tempDir := check.MustValue(os.MkdirTemp("", "clc-"))
outDir := filepath.Join(tempDir, "my-project")
fixture := filepath.Join(testDir, "fixture", "simple")
defer func() {
// ignoring the error here
_ = os.RemoveAll(outDir)
}()
ctx := context.Background()
// logging to stderr in order to avoid creating the logs directory
cmd := []string{"project", "create", "simple", "-o", outDir, "--log.path", "stderr", "another_key=foo", "key1=bar"}
check.Must(tcx.CLC().Execute(ctx, cmd...))
check.Must(compareDirectories(fixture, outDir))
})
testHomeDir := "testdata/home"
check.Must(paths.CopyDir(testHomeDir, tcx.HomePath()))
tempDir := check.MustValue(os.MkdirTemp("", "clc-"))
outDir := filepath.Join(tempDir, "my-project")
fixtureDir := "testdata/fixture/simple"
defer func() {
// ignoring the error here
_ = os.RemoveAll(outDir)
}()
ctx := context.Background()
// logging to stderr in order to avoid creating the logs directory
cmd := []string{"project", "create", "simple", "-o", outDir, "--log.path", "stderr", "another_key=foo", "key1=bar"}
check.Must(tcx.CLC().Execute(ctx, cmd...))
check.Must(compareDirectories(fixtureDir, outDir))
})
}

Expand Down
66 changes: 66 additions & 0 deletions base/commands/project/project_list_it_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package project

import (
"context"
"encoding/json"
"os"
"path/filepath"
"strconv"
"testing"
"time"

"github.com/hazelcast/hazelcast-commandline-client/clc/paths"
"github.com/hazelcast/hazelcast-commandline-client/clc/store"
"github.com/hazelcast/hazelcast-commandline-client/internal/check"
"github.com/hazelcast/hazelcast-commandline-client/internal/it"
"github.com/hazelcast/hazelcast-commandline-client/internal/log"
)

func TestProjectListCommand(t *testing.T) {
testCases := []struct {
name string
f func(t *testing.T)
}{
{name: "ProjectList_CachedTest", f: projectList_CachedTest},
{name: "ProjectList_LocalTest", f: projectList_LocalTest},
}
for _, tc := range testCases {
t.Run(tc.name, tc.f)
}
}

func projectList_CachedTest(t *testing.T) {
tcx := it.TestContext{T: t}
tcx.Tester(func(tcx it.TestContext) {
sPath := filepath.Join(paths.Caches(), "templates")
defer func() {
os.RemoveAll(sPath)
}()
sa := store.NewStoreAccessor(sPath, log.NopLogger{})
check.MustValue(sa.WithLock(func(s *store.Store) (any, error) {
v := []byte(strconv.FormatInt(time.Now().Add(cacheRefreshInterval).Unix(), 10))
err := s.SetEntry([]byte(nextFetchTimeKey), v)
return nil, err
}))
check.MustValue(sa.WithLock(func(s *store.Store) (any, error) {
b := check.MustValue(json.Marshal([]Template{{Name: "test_template"}}))
err := s.SetEntry([]byte(templatesKey), b)
return nil, err
}))
cmd := []string{"project", "list-templates"}
check.Must(tcx.CLC().Execute(context.Background(), cmd...))
tcx.AssertStdoutContains("test_template")
})
}

func projectList_LocalTest(t *testing.T) {
tcx := it.TestContext{T: t}
tcx.Tester(func(tcx it.TestContext) {
testHomeDir := "testdata/home"
check.Must(paths.CopyDir(testHomeDir, tcx.HomePath()))
cmd := []string{"project", "list-templates", "--local"}
check.Must(tcx.CLC().Execute(context.Background(), cmd...))
tcx.AssertStdoutContains("simple")
tcx.AssertStdoutContains("local")
})
}
Loading

0 comments on commit 286456a

Please sign in to comment.