Skip to content

Add events and metadata tests #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/devfile/library
go 1.13

require (
github.com/devfile/api/v2 v2.0.0-20210615212757-b0014e012b86
github.com/devfile/api/v2 v2.0.0-20210623152004-b08e48618403
github.com/fatih/color v1.7.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gobwas/glob v0.2.3
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devfile/api/v2 v2.0.0-20210615212757-b0014e012b86 h1:UmscUfwS9gUpM1cPdfuewwPDrXCA5cy8WEJ1HQDgtSA=
github.com/devfile/api/v2 v2.0.0-20210615212757-b0014e012b86/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
github.com/devfile/api/v2 v2.0.0-20210623152004-b08e48618403 h1:5Cyt6BucdDKwaW1LaftbJt6P2tpR1GjF/b9GpO5NFmg=
github.com/devfile/api/v2 v2.0.0-20210623152004-b08e48618403/go.mod h1:QNzaIVQnCsYfXed+QZOn1uvEQFzyhvpi/uc3g/b2ws0=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
Expand Down Expand Up @@ -271,6 +271,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb h1:w1g9wNDIE/pHSTmAaUhv4TZQuPBS6GV3mMz5hkgziIU=
github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb/go.mod h1:5ELEyG+X8f+meRWHuqUOewBOhvHkl7M76pdGEansxW4=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
52 changes: 43 additions & 9 deletions tests/v2/libraryTest/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ import (
libraryUtils "github.com/devfile/library/tests/v2/utils/library"
)

// TestContent - structure used by a test to configure the tests to run
type TestContent struct {
CommandTypes []schema.CommandType
ComponentTypes []schema.ComponentType
FileName string
EditContent bool
}

func Test_ExecCommand(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AddEvents randomly set event values: https://github.com/devfile/api/blob/b08e48618403f7102592389e621531145bdfcbcc/test/v200/utils/common/events-utils.go#L35
looks like you cannot control to be only Exec or Apply or composite command.
Should not be under test for each particular type of command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see what you mean. SetEventValues will create extra commands that will be outside the scope of the Exec testing, so I need to narrow this down to just the commands that Exec or composite Exec supports

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the easiest thing to do in this case is what you suggested; to remove events testing in these scenarios (otherwise I'd have to introduce new functions in the api utils). I added new events test cases similar to what's being done in api tests, so that should ensure sufficient coverage.

testContent.EditContent = false
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand All @@ -27,6 +20,7 @@ func Test_ExecCommand(t *testing.T) {
func Test_ExecCommandEdit(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
testContent.EditContent = true
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand All @@ -36,6 +30,7 @@ func Test_ExecCommandEdit(t *testing.T) {
func Test_ApplyCommand(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.ApplyCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
testContent.EditContent = false
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand All @@ -45,6 +40,7 @@ func Test_ApplyCommand(t *testing.T) {
func Test_ApplyCommandEdit(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.ApplyCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
testContent.EditContent = true
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand All @@ -54,6 +50,7 @@ func Test_ApplyCommandEdit(t *testing.T) {
func Test_CompositeCommand(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.CompositeCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
testContent.EditContent = false
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand All @@ -62,6 +59,7 @@ func Test_CompositeCommand(t *testing.T) {
func Test_CompositeCommandEdit(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.CompositeCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
testContent.EditContent = true
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand All @@ -73,6 +71,7 @@ func Test_MultiCommand(t *testing.T) {
testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType,
schema.CompositeCommandType,
schema.ApplyCommandType}
testContent.AddEvents = commonUtils.GetBinaryDecision()
testContent.EditContent = true
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand Down Expand Up @@ -179,12 +178,47 @@ func Test_StarterProjects(t *testing.T) {
libraryUtils.RunMultiThreadTest(testContent, t)
}

func Test_Metadata(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.AddMetaData = true
testContent.EditContent = false
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
libraryUtils.RunMultiThreadTest(testContent, t)
}

func Test_MetadataEdit(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.AddMetaData = true
testContent.EditContent = true
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
libraryUtils.RunMultiThreadTest(testContent, t)
}

func Test_Everything(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType, schema.CompositeCommandType, schema.ApplyCommandType}
testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType, schema.VolumeComponentType}
testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType, schema.KubernetesComponentType, schema.OpenshiftComponentType, schema.VolumeComponentType}
testContent.ProjectTypes = []schema.ProjectSourceType{schema.GitProjectSourceType, schema.ZipProjectSourceType}
testContent.StarterProjectTypes = []schema.ProjectSourceType{schema.GitProjectSourceType, schema.ZipProjectSourceType}
testContent.AddEvents = true
testContent.AddMetaData = true
testContent.EditContent = false
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
libraryUtils.RunMultiThreadTest(testContent, t)

}

func Test_EverythingEdit(t *testing.T) {
testContent := commonUtils.TestContent{}
testContent.CommandTypes = []schema.CommandType{schema.ExecCommandType, schema.CompositeCommandType, schema.ApplyCommandType}
testContent.ComponentTypes = []schema.ComponentType{schema.ContainerComponentType, schema.KubernetesComponentType, schema.OpenshiftComponentType, schema.VolumeComponentType}
testContent.ProjectTypes = []schema.ProjectSourceType{schema.GitProjectSourceType, schema.ZipProjectSourceType}
testContent.StarterProjectTypes = []schema.ProjectSourceType{schema.GitProjectSourceType, schema.ZipProjectSourceType}
testContent.AddEvents = true
testContent.AddMetaData = true
testContent.EditContent = true
testContent.FileName = commonUtils.GetDevFileName()
libraryUtils.RunTest(testContent, t)
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/utils/library/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (devfileFollower DevfileFollower) AddEvent(event schema.Events) error {

// UpdateEvent updates the specified event in the library data
func (devfileFollower DevfileFollower) UpdateEvent(event schema.Events) {
devfileFollower.LibraryData.UpdateEvents(event.PreStart, event.PostStart, event.PreStop, event.PostStop)
devfileFollower.LibraryData.UpdateEvents(event.PostStart, event.PostStop, event.PreStart, event.PreStop)
}

// SetParent sets the specified parent in the library data
Expand Down