Skip to content

Commit

Permalink
Fix using create cluster will cause runtime error that index out of r…
Browse files Browse the repository at this point in the history
…ange (#93)
  • Loading branch information
hbpen authored Jul 2, 2023
1 parent 77fe35f commit ef4a945
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/client/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ func (e *Executor) create(words []string) (err error) {
err = e.request.CreateNamespace(namespace)
case promptStateNamespace:
ns := e.promptCtx.namespace
if len(words) < 3 {
return ErrWrongArguments
}
if words[1] != typeCluster {
return fmt.Errorf("cannot create '%s' in namespace state", words[2])
}
Expand Down
37 changes: 37 additions & 0 deletions cmd/client/executor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

package main

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_create(t *testing.T) {
request := NewRequest(config.Endpoint)
promptCtx := NewPromptContext()
executor := NewExecutor(promptCtx, request)

executor.promptCtx.state = promptStateNamespace
words := [...]string{"create", "cluster"}
require.EqualError(t, executor.create(words[:]), ErrWrongArguments.Error())
}

0 comments on commit ef4a945

Please sign in to comment.