-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gergely Brautigam
committed
Sep 3, 2019
1 parent
e4744b9
commit ba5371f
Showing
5 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,104 @@ | ||
package store | ||
|
||
// Thar be some tests here soon. | ||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/gaia-pipeline/gaia" | ||
) | ||
|
||
func TestGetSHAPAir(t *testing.T) { | ||
// Create tmp folder | ||
tmp, err := ioutil.TempDir("", "TestGetSHAPAir") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmp) | ||
|
||
store := NewBoltStore() | ||
gaia.Cfg.Bolt.Mode = 0600 | ||
err = store.Init(tmp) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer store.Close() | ||
|
||
pair := gaia.SHAPair{} | ||
pair.UniqueID = "unique-id" | ||
pair.Original = []byte("original") | ||
pair.Worker = []byte("worker") | ||
err = store.UpsertSHAPair(pair) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ok, p, err := store.GetSHAPair([]byte(pair.UniqueID)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !ok { | ||
t.Fatalf("sha pair not found") | ||
} | ||
|
||
if p.UniqueID != pair.UniqueID { | ||
t.Fatalf("unique id match error. want %s got %s", pair.UniqueID, p.UniqueID) | ||
} | ||
if !bytes.Equal(p.Worker, pair.Worker) { | ||
t.Fatalf("worker sha match error. want %s got %s", pair.Worker, p.Worker) | ||
} | ||
if !bytes.Equal(p.Original, pair.Original) { | ||
t.Fatalf("original sha match error. want %s got %s", pair.Original, p.Original) | ||
} | ||
} | ||
|
||
func TestUpsertSHAPair(t *testing.T) { | ||
// Create tmp folder | ||
tmp, err := ioutil.TempDir("", "TestUpsertSHAPair") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmp) | ||
|
||
store := NewBoltStore() | ||
gaia.Cfg.Bolt.Mode = 0600 | ||
err = store.Init(tmp) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer store.Close() | ||
|
||
pair := gaia.SHAPair{} | ||
pair.UniqueID = "unique-id" | ||
pair.Original = []byte("original") | ||
pair.Worker = []byte("worker") | ||
err = store.UpsertSHAPair(pair) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// Test is upsert overwrites existing records. | ||
pair.Original = []byte("original2") | ||
err = store.UpsertSHAPair(pair) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ok, p, err := store.GetSHAPair([]byte(pair.UniqueID)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !ok { | ||
t.Fatalf("sha pair not found") | ||
} | ||
|
||
if p.UniqueID != pair.UniqueID { | ||
t.Fatalf("unique id match error. want %s got %s", pair.UniqueID, p.UniqueID) | ||
} | ||
if !bytes.Equal(p.Worker, pair.Worker) { | ||
t.Fatalf("worker sha match error. want %s got %s", pair.Worker, p.Worker) | ||
} | ||
if !bytes.Equal(p.Original, pair.Original) { | ||
t.Fatalf("original sha match error. want %s got %s", pair.Original, p.Original) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters