Skip to content

Commit

Permalink
feat: changing DONE message to OK (zurvan-lab#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
kehiy committed Jan 2, 2024
1 parent 1a696f6 commit 3ca9522
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/commands/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func REPLCommand(parentCmd *cobra.Command) {
conQuery := fmt.Sprintf("CON %v %v", *username, *password)

response := do(conn, conQuery)
if response == "DONE" {
if response == "OK" {
reader := bufio.NewReader(os.Stdin)

for {
Expand Down
2 changes: 1 addition & 1 deletion core/TQL/execute/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestExecute(t *testing.T) {

_, ok := db.SetsMap()["testSet"]

assert.Equal(t, "DONE", eResult)
assert.Equal(t, "OK", eResult)
assert.True(t, ok)

q2 := core.ParseQuery("CNTS")
Expand Down
18 changes: 9 additions & 9 deletions core/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (db *Database) Connect(args []string) string {

for _, u := range db.Config.Users {
if u.Name == args[0] && u.Password == args[1] {
return DONE
return OK
}
}

Expand All @@ -59,7 +59,7 @@ func (db *Database) AddSet(args []string) string {

db.Sets[args[0]] = make(Set) // args[0] is set name. see: TQL docs.

return DONE
return OK
}

func (db *Database) AddSubSet(args []string) string {
Expand All @@ -77,7 +77,7 @@ func (db *Database) AddSubSet(args []string) string {

s[args[1]] = make(SubSet, 0) // subset name args[1]

return DONE
return OK
}

func (db *Database) PushElement(args []string) string {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (db *Database) PushElement(args []string) string {

db.Sets[setName][subSetName] = append(db.Sets[setName][subSetName], e)

return DONE
return OK
}

func (db *Database) DropSet(args []string) string {
Expand All @@ -128,7 +128,7 @@ func (db *Database) DropSet(args []string) string {

delete(db.Sets, setName)

return DONE
return OK
}

func (db *Database) DropSubSet(args []string) string {
Expand All @@ -149,7 +149,7 @@ func (db *Database) DropSubSet(args []string) string {

delete(db.Sets[setName], subSetName)

return DONE
return OK
}

func (db *Database) CleanSets(_ []string) string {
Expand All @@ -158,7 +158,7 @@ func (db *Database) CleanSets(_ []string) string {

db.Sets = make(Sets)

return DONE
return OK
}

func (db *Database) CleanSet(args []string) string {
Expand All @@ -178,7 +178,7 @@ func (db *Database) CleanSet(args []string) string {

db.Sets[setName] = make(Set)

return DONE
return OK
}

func (db *Database) CleanSubSet(args []string) string {
Expand All @@ -199,7 +199,7 @@ func (db *Database) CleanSubSet(args []string) string {

db.Sets[setName][subSetName] = make(SubSet, 0)

return DONE
return OK
}

func (db *Database) CountSets(_ []string) string {
Expand Down
16 changes: 8 additions & 8 deletions core/database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ func TestDataBase(t *testing.T) {
result := db.AddSet([]string{"testSet"})

assert.Equal(t, 1, len(db.SetsMap()))
assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)
})

t.Run("AddSubSetTest", func(t *testing.T) {
db.AddSet([]string{"testSet"})
result := db.AddSubSet([]string{"testSet", "testSubSet"})

assert.Equal(t, 0, len(db.SetsMap()["testSet"]["testSubSet"]))
assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)

result = db.AddSubSet([]string{"testInvalidSet", "testSubSet"})

Expand All @@ -40,7 +40,7 @@ func TestDataBase(t *testing.T) {
timeStr := fmt.Sprintf("%d", time.Now().Unix())
result := db.PushElement([]string{"testSet", "testSubSet", "testValue", timeStr})

assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)
assert.Equal(t, 1, len(db.SetsMap()["testSet"]["testSubSet"]))
assert.Equal(t, "testValue", db.SetsMap()["testSet"]["testSubSet"][0].value)

Expand All @@ -65,7 +65,7 @@ func TestDataBase(t *testing.T) {
result := db.DropSet([]string{"testSet"})

assert.Equal(t, 2, len(db.SetsMap()))
assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)

result = db.DropSet([]string{"inavlidTestSet"})

Expand All @@ -82,7 +82,7 @@ func TestDataBase(t *testing.T) {

result := db.DropSubSet([]string{"testSet", "subSetOne"})

assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)
assert.Equal(t, 1, len(db.SetsMap()["testSet"]))
assert.Nil(t, db.SetsMap()["testSet"]["subSetOne"])

Expand Down Expand Up @@ -111,17 +111,17 @@ func TestDataBase(t *testing.T) {

result := db.CleanSubSet([]string{"secondTestSet", "subSetTwo"})

assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)
assert.Equal(t, 0, len(db.SetsMap()["secondTestSet"]["subSetTwo"]))

result = db.CleanSet([]string{"testSet"})

assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)
assert.Equal(t, 0, len(db.SetsMap()["testSet"]))

result = db.CleanSets([]string{})

assert.Equal(t, DONE, result)
assert.Equal(t, OK, result)
assert.Equal(t, 0, len(db.SetsMap()))

result = db.CleanSet([]string{"invalidSet"})
Expand Down
2 changes: 1 addition & 1 deletion core/database/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

const (
INVALID = "INVALID"
DONE = "DONE"
OK = "OK"
PONG = "PONG"
SET_NOT_FOUND = "SNF"
SUB_SET_NOT_FOUND = "SSNF"
Expand Down
2 changes: 1 addition & 1 deletion core/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s *Server) Authenticate(conn net.Conn) (*config.User, error) {
}

result := execute.Execute(query, s.db)
if result != database.DONE {
if result != database.OK {
_ = conn.Close()

return nil, errors.ErrAuth
Expand Down
2 changes: 1 addition & 1 deletion doc/TQL/TQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Time trace is using a query language called TQL. Here is documentation and speci

| Message | reason |
|----------|:-------------|
| DONE | everything is ok |
| OK | everything is OK |
| INVALID | invalid user and password to make a connection OR not enough args for a command |
| SNF | set is not found |
| SSNF | subset is not found |
Expand Down

0 comments on commit 3ca9522

Please sign in to comment.