Skip to content
Snippets Groups Projects
Select Git revision
  • 005637e66ba0afaaf4b8d62d7a65b791c71d14fd
  • release default
  • master protected
  • hotfix/gtnNoToken
  • XX-4441
  • Jakub/rootless-CI
  • jonah/refactorProviders
  • Ace/Huawei
  • AceVentura/AccountBackup
  • hotfix/delete-error
  • waitingRoundsRewrite
  • dev
  • quantumSecure
  • hotfix/ratelimit
  • fullRateLimit
  • XX-3564/TlsCipherSuite
  • hotfix/notifications-db
  • hotfix/groupNotification
  • Project/LastMile
  • notls
  • url-repo-rename
  • v2.3.0
  • v2.2.0
  • v2.1.0
  • v2.0.0
  • v1.0.0
26 results

ephemeral_test.go

Blame
  • jbhusson's avatar
    Jonah Husson authored
    005637e6
    History
    ephemeral_test.go 2.67 KiB
    package notifications
    
    import (
    	"fmt"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/notifications-bot/storage"
    	"gitlab.com/xx_network/comms/connect"
    	"gitlab.com/xx_network/primitives/id"
    	"gitlab.com/xx_network/primitives/id/ephemeral"
    	"os"
    	"testing"
    	"time"
    )
    
    func TestMain(m *testing.M) {
    	jww.SetStdoutThreshold(jww.LevelTrace)
    	connect.TestingOnlyDisableTLS = true
    	os.Exit(m.Run())
    }
    
    func TestImpl_InitDeleter(t *testing.T) {
    	s, err := storage.NewStorage("", "", "", "", "")
    	if err != nil {
    		t.Errorf("Failed to init storage: %+v", err)
    	}
    	impl := &Impl{
    		Storage: s,
    	}
    	uid := id.NewIdFromString("zezima", id.User, t)
    	iid, err := ephemeral.GetIntermediaryId(uid)
    	if err != nil {
    		t.Errorf("Failed to get intermediary ephemeral id: %+v", err)
    	}
    	if err != nil {
    		t.Fatalf("Could not parse precanned time: %v", err.Error())
    	}
    	u, err := s.AddUser(iid, []byte("trsa"), []byte("Sig"), "token")
    	if err != nil {
    		t.Errorf("Failed to add user to storage: %+v", err)
    	}
    	_, epoch := ephemeral.HandleQuantization(time.Now().Add(-30 * time.Hour))
    	e, err := s.AddLatestEphemeral(u, epoch, 16)
    	if err != nil {
    		t.Errorf("Failed to add latest ephemeral for user: %+v", err)
    	}
    	elist, err := s.GetEphemeral(e.EphemeralId)
    	if err != nil {
    		t.Errorf("Failed to get latest ephemeral for user: %+v", err)
    	}
    	if elist == nil {
    		t.Error("Did not receive ephemeral for user")
    	}
    	impl.initDeleter()
    	time.Sleep(time.Second * 5)
    	elist, err = s.GetEphemeral(e.EphemeralId)
    	if err == nil {
    		t.Errorf("Ephemeral should have been deleted, did not receive error: %+v", e)
    	}
    }
    
    func TestImpl_InitCreator(t *testing.T) {
    	s, err := storage.NewStorage("", "", "", "", "")
    	if err != nil {
    		t.Errorf("Failed to init storage: %+v", err)
    		t.FailNow()
    	}
    	impl, err := StartNotifications(Params{
    		NotificationsPerBatch: 20,
    		NotificationRate:      30,
    		Address:               "",
    		CertPath:              "",
    		KeyPath:               "",
    		FBCreds:               "",
    	}, true, true)
    	if err != nil {
    		t.Errorf("Failed to create impl: %+v", err)
    		t.FailNow()
    	}
    	impl.Storage = s
    	uid := id.NewIdFromString("zezima", id.User, t)
    	iid, err := ephemeral.GetIntermediaryId(uid)
    	if err != nil {
    		t.Errorf("Failed to get intermediary ephemeral id: %+v", err)
    	}
    	if err != nil {
    		t.Errorf("Could not parse precanned time: %v", err.Error())
    	}
    	u, err := s.AddUser(iid, []byte("trsa"), []byte("Sig"), "token")
    	if err != nil {
    		t.Errorf("Failed to add user to storage: %+v", err)
    	}
    	fmt.Println(u.OffsetNum)
    	impl.initCreator()
    	e, err := s.GetLatestEphemeral()
    	if err != nil {
    		t.Errorf("Failed to get latest ephemeral: %+v", err)
    	}
    	if e == nil {
    		t.Error("Did not receive ephemeral for user")
    	}
    }