Skip to content

Commit

Permalink
add test for create index
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhatsharma committed May 8, 2022
1 parent da8b770 commit 5a24712
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pkg/handlers/bulk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
* 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 handlers

import (
"io"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -59,7 +58,5 @@ func TestBulkHandlerWorker(t *testing.T) {
assert.Equal(t, got.Items[0]["index"].Status, 200)
assert.Equal(t, got.Items[1]["index"].Status, 200)
})

os.RemoveAll("data")
}
}
63 changes: 63 additions & 0 deletions pkg/handlers/createindex_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright 2022 Zinc Labs Inc. and Contributors
*
* Licensed 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 handlers

import (
"math/rand"
"os"
"strconv"
"testing"
"time"

"github.com/zinclabs/zinc/pkg/core"
)

func TestCreateIndexWorker(t *testing.T) {
os.Setenv("ZINC_FIRST_ADMIN_USER", "admin")
os.Setenv("ZINC_FIRST_ADMIN_PASSWORD", "Complexpass#123")

type args struct {
newIndex *core.Index
indexName string
}
tests := []struct {
name string
args args
wantErr bool
}{
// TODO: Add test cases.
{
name: "test1",
args: args{
newIndex: &core.Index{
StorageType: "disk",
},
indexName: "test1",
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rand.Seed(time.Now().UnixNano())
id := rand.Intn(1000)

if err := CreateIndexWorker(tt.args.newIndex, tt.args.indexName+strconv.Itoa(id)); (err != nil) != tt.wantErr {
t.Errorf("CreateIndexWorker() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 5a24712

Please sign in to comment.