Skip to content

Commit

Permalink
Merge branch 'main' into CLC-258
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Aug 29, 2023
2 parents 5717a04 + 1acb688 commit f950eb2
Show file tree
Hide file tree
Showing 62 changed files with 1,085 additions and 320 deletions.
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 @@ -4,7 +4,7 @@ GIT_COMMIT = $(shell git rev-parse HEAD 2> /dev/null || echo unknown)
CLC_VERSION ?= v0.0.0-CUSTOMBUILD
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: 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 f950eb2

Please sign in to comment.