Skip to content

Commit

Permalink
add: session test
Browse files Browse the repository at this point in the history
test: add set and get containers  user data test

test: add set and get images  user data test

test: add set and get current container user data test

test: add set and get current image user data test

test: add set and get scene user data test
  • Loading branch information
ezzoddin authored and arshamalh committed Dec 20, 2023
1 parent c4b422e commit 3a2fd06
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
19 changes: 19 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package session_test

import (
"github.com/arshamalh/dockeroller/session"
"github.com/stretchr/testify/assert"
"testing"
)

func TestNewSession(t *testing.T) {
assert := assert.New(t)
t.Run("new session", func(t *testing.T) {
s := session.New()

var userID int64 = 2
userData := s.Get(userID)

assert.NotNil(userData)
})
}
109 changes: 109 additions & 0 deletions session/userdata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package session_test

import (
"github.com/arshamalh/dockeroller/entities"
"github.com/arshamalh/dockeroller/session"
"github.com/go-faker/faker/v4"

Check failure on line 6 in session/userdata_test.go

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/go-faker/faker/v4; to add it:
"github.com/stretchr/testify/assert"
"testing"
)

func TestUserData(t *testing.T) {
assert := assert.New(t)
t.Run("set and get containers", func(t *testing.T) {
s := session.New()
userData := s.Get(2)
fakeContainers := newFakeContainers()

userData.SetContainers(fakeContainers)
userContainers := userData.GetContainers()

assert.NotNil(userContainers)
for _, userContainer := range userContainers {
assert.NotNil(userContainer)
}
})

t.Run("set and get current container", func(t *testing.T) {
s := session.New()
userData := s.Get(2)
fakeContainers := newFakeContainers()

userData.SetCurrentContainer(fakeContainers[1])
userCurrentContainer := userData.GetCurrentContainer()

assert.NotNil(userCurrentContainer)
})

t.Run("set and get images", func(t *testing.T) {
s := session.New()
userData := s.Get(2)
fakeImages := newFakeImages()

userData.SetImages(fakeImages)
userImages := userData.GetImages()

assert.NotNil(userImages)
for _, userImage := range userImages {
assert.NotNil(userImage)
}
})

t.Run("set and get current image", func(t *testing.T) {
s := session.New()
userData := s.Get(2)
fakeImages := newFakeImages()

userData.SetCurrentImage(fakeImages[1])
userCurrentImage := userData.GetCurrentImage()

assert.NotNil(userCurrentImage)
})

t.Run("set and get scene", func(t *testing.T) {
s := session.New()
userData := s.Get(2)

userData.SetScene(entities.SceneRenameImage)
scene := userData.GetScene()

assert.NotNil(scene)
assert.Equal(userData.CurrentQuestion, entities.QNewImageName)

userData.SetScene(entities.SceneRenameContainer)
scene = userData.GetScene()

assert.NotNil(scene)
assert.Equal(userData.CurrentQuestion, entities.QNewContainerName)
})
}

func newFakeContainers() []*entities.Container {
var containers []*entities.Container
for i := 0; i < 3; i++ {
containers = append(containers, &entities.Container{
ID: faker.UUIDDigit(),
Name: faker.Word(),
State: entities.ContainerStateRunning,
Image: faker.Word(),
Status: faker.Word(),
})
}

return containers
}

func newFakeImages() []*entities.Image {
var images []*entities.Image
for i := 0; i < 3; i++ {
images = append(images, &entities.Image{
ID: faker.UUIDDigit(),
Size: 12,
Tags: []string{faker.Word(), faker.WORD},
Status: entities.ImageStatusInUse,
CreatedAt: faker.TIMESTAMP,
})
}

return images
}

0 comments on commit 3a2fd06

Please sign in to comment.