Skip to content

Commit

Permalink
fixing up a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 22, 2024
1 parent 0e5ee80 commit 6c226ff
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 30 deletions.
23 changes: 12 additions & 11 deletions repomgr/ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestLoadNewRepo(t *testing.T) {
}
}

func testCarstore(t *testing.T, dir string) carstore.CarStore {
func testCarstore(t *testing.T, dir string, archive bool) carstore.CarStore {
cardb, err := gorm.Open(sqlite.Open(filepath.Join(dir, "car.sqlite")))
if err != nil {
t.Fatal(err)
Expand All @@ -80,19 +80,20 @@ func testCarstore(t *testing.T, dir string) carstore.CarStore {
t.Fatal(err)
}

/*
if archive {
cs, err := carstore.NewCarStore(cardb, []string{cspath})
if err != nil {
t.Fatal(err)
}
*/
return cs
} else {
cs, err := carstore.NewNonArchivalCarstore(cardb)
if err != nil {
t.Fatal(err)
}

cs, err := carstore.NewNonArchivalCarstore(cardb)
if err != nil {
t.Fatal(err)
return cs
}

return cs
}

func TestIngestWithGap(t *testing.T) {
Expand All @@ -113,15 +114,15 @@ func TestIngestWithGap(t *testing.T) {
Uid: 1,
})

cs := testCarstore(t, dir)
cs := testCarstore(t, dir, true)

repoman := NewRepoManager(cs, &util.FakeKeyManager{})

dir2, err := os.MkdirTemp("", "integtest")
if err != nil {
t.Fatal(err)
}
cs2 := testCarstore(t, dir2)
cs2 := testCarstore(t, dir2, true)

var since *string
ctx := context.TODO()
Expand Down Expand Up @@ -205,7 +206,7 @@ func TestDuplicateRecord(t *testing.T) {
Uid: 1,
})

cs := testCarstore(t, dir)
cs := testCarstore(t, dir, true)

repoman := NewRepoManager(cs, &util.FakeKeyManager{})

Expand Down
36 changes: 28 additions & 8 deletions testing/integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ func init() {
}

func TestRelayBasic(t *testing.T) {
t.Helper()
testRelayBasic(t, true)
}

func TestRelayBasicNonArchive(t *testing.T) {
t.Helper()
testRelayBasic(t, false)
}

func testRelayBasic(t *testing.T, archive bool) {
if testing.Short() {
t.Skip("skipping Relay test in 'short' test mode")
}
Expand All @@ -33,7 +43,7 @@ func TestRelayBasic(t *testing.T) {
p1 := MustSetupPDS(t, ".tpds", didr)
p1.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, archive)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost()}
Expand Down Expand Up @@ -116,6 +126,16 @@ func socialSim(t *testing.T, users []*TestUser, postiter, likeiter int) []*atpro
}

func TestRelayMultiPDS(t *testing.T) {
t.Helper()
testRelayMultiPDS(t, true)
}

func TestRelayMultiPDSNonArchive(t *testing.T) {
t.Helper()
testRelayMultiPDS(t, false)
}

func testRelayMultiPDS(t *testing.T, archive bool) {
if testing.Short() {
t.Skip("skipping Relay test in 'short' test mode")
}
Expand All @@ -130,7 +150,7 @@ func TestRelayMultiPDS(t *testing.T) {
p2 := MustSetupPDS(t, ".pdsdos", didr)
p2.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, archive)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost(), p2.RawHost()}
Expand Down Expand Up @@ -198,7 +218,7 @@ func TestRelayMultiGap(t *testing.T) {
p2 := MustSetupPDS(t, ".pdsdos", didr)
p2.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, true)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost(), p2.RawHost()}
Expand Down Expand Up @@ -256,7 +276,7 @@ func TestHandleChange(t *testing.T) {
p1 := MustSetupPDS(t, ".pdsuno", didr)
p1.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, true)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost()}
Expand Down Expand Up @@ -293,7 +313,7 @@ func TestAccountEvent(t *testing.T) {
p1 := MustSetupPDS(t, ".pdsuno", didr)
p1.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, true)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost()}
Expand Down Expand Up @@ -401,7 +421,7 @@ func TestRelayTakedown(t *testing.T) {
p1 := MustSetupPDS(t, ".tpds", didr)
p1.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, true)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost()}
Expand Down Expand Up @@ -480,7 +500,7 @@ func TestDomainBans(t *testing.T) {
}
didr := TestPLC(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, true)
b1.Run(t)

b1.BanDomain(t, "foo.com")
Expand Down Expand Up @@ -523,7 +543,7 @@ func TestRelayHandleEmptyEvent(t *testing.T) {
p1 := MustSetupPDS(t, ".tpds", didr)
p1.Run(t)

b1 := MustSetupRelay(t, didr)
b1 := MustSetupRelay(t, didr, true)
b1.Run(t)

b1.tr.TrialHosts = []string{p1.RawHost()}
Expand Down
24 changes: 13 additions & 11 deletions testing/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,18 @@ func (t *TestRelay) Host() string {
return t.listener.Addr().String()
}

func MustSetupRelay(t *testing.T, didr plc.PLCClient) *TestRelay {
func MustSetupRelay(t *testing.T, didr plc.PLCClient, archive bool) *TestRelay {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
tbgs, err := SetupRelay(ctx, didr)
tbgs, err := SetupRelay(ctx, didr, archive)
if err != nil {
t.Fatal(err)
}

return tbgs
}

func SetupRelay(ctx context.Context, didr plc.PLCClient) (*TestRelay, error) {
func SetupRelay(ctx context.Context, didr plc.PLCClient, archive bool) (*TestRelay, error) {
dir, err := os.MkdirTemp("", "integtest")
if err != nil {
return nil, err
Expand All @@ -550,18 +550,20 @@ func SetupRelay(ctx context.Context, didr plc.PLCClient) (*TestRelay, error) {
return nil, err
}

/*
cs, err := carstore.NewCarStore(cardb, []string{cspath})
var cs carstore.CarStore
if archive {
arccs, err := carstore.NewCarStore(cardb, []string{cspath})
if err != nil {
return nil, err
}
//*/
//*
cs, err := carstore.NewNonArchivalCarstore(cardb)
if err != nil {
return nil, err
cs = arccs
} else {
nacs, err := carstore.NewNonArchivalCarstore(cardb)
if err != nil {
return nil, err
}
cs = nacs
}
//*/

//kmgr := indexer.NewKeyManager(didr, nil)
kmgr := &bsutil.FakeKeyManager{}
Expand Down

0 comments on commit 6c226ff

Please sign in to comment.