1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/abap/build/bfw_test.go
tiloKo b81b11ca9d
abapEnvironmentAssemblePackages new Features (#2661)
* Unit Test Assemble Package

* Remove obsolete lines

dust wiping

* climate change

* climate change #2

* climate change #3

* climate change #4

* climate change #5

* NSPC serial builds

* Actual Delivery Commit

* Download Delivery_logs.zip

* Publish Result

* Testing

* !Polling

* Provide Commit to BF only if set

* dust wiping

* More Dust to Wipe

* Publish more than on file

* Write Log for Publish

* fix unit test (now Dummy Entries)

* save one line of code for climate change

* Update cmd/abapEnvironmentAssemblePackages.go

Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>

* More Detailed Log Messages

Co-authored-by: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com>
2021-03-11 11:55:12 +01:00

116 lines
3.2 KiB
Go

package build
import (
"testing"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/stretchr/testify/assert"
)
func testSetup(client piperhttp.Sender, buildID string) Build {
conn := new(Connector)
conn.Client = client
conn.DownloadClient = &DownloadClientMock{}
conn.Header = make(map[string][]string)
b := Build{
Connector: *conn,
BuildID: buildID,
}
return b
}
func TestStart(t *testing.T) {
t.Run("Run start", func(t *testing.T) {
client := &ClMock{
Token: "MyToken",
}
b := testSetup(client, "")
inputValues := Values{
Values: []Value{
{
ValueID: "PACKAGES",
Value: "/BUILD/CORE",
},
{
ValueID: "season",
Value: "winter",
},
},
}
err := b.Start("test", inputValues)
assert.NoError(t, err)
assert.Equal(t, Accepted, b.RunState)
})
}
func TestGet(t *testing.T) {
t.Run("Run Get", func(t *testing.T) {
b := testSetup(&ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
err := b.Get()
assert.NoError(t, err)
assert.Equal(t, Finished, b.RunState)
assert.Equal(t, 0, len(b.Tasks))
})
}
func TestGetTasks(t *testing.T) {
t.Run("Run getTasks", func(t *testing.T) {
b := testSetup(&ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
assert.Equal(t, 0, len(b.Tasks))
err := b.getTasks()
assert.NoError(t, err)
assert.Equal(t, b.Tasks[0].TaskID, 0)
assert.Equal(t, b.Tasks[0].PluginClass, "")
assert.Equal(t, b.Tasks[1].TaskID, 1)
assert.Equal(t, b.Tasks[1].PluginClass, "/BUILD/CL_TEST_PLUGIN_OK")
})
}
func TestGetLogs(t *testing.T) {
t.Run("Run getLogs", func(t *testing.T) {
b := testSetup(&ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
err := b.getLogs()
assert.NoError(t, err)
assert.Equal(t, "I:/BUILD/LOG:000 ABAP Build Framework", b.Tasks[0].Logs[0].Logline)
assert.Equal(t, loginfo, b.Tasks[0].Logs[0].Msgty)
assert.Equal(t, "W:/BUILD/LOG:000 We can even have warnings!", b.Tasks[1].Logs[1].Logline)
assert.Equal(t, logwarning, b.Tasks[1].Logs[1].Msgty)
})
}
func TestGetValues(t *testing.T) {
t.Run("Run getValues", func(t *testing.T) {
b := testSetup(&ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
assert.Equal(t, 0, len(b.Values))
err := b.getValues()
assert.NoError(t, err)
assert.Equal(t, 4, len(b.Values))
assert.Equal(t, "PHASE", b.Values[0].ValueID)
assert.Equal(t, "test1", b.Values[0].Value)
assert.Equal(t, "PACKAGES", b.Values[1].ValueID)
assert.Equal(t, "/BUILD/CORE", b.Values[1].Value)
assert.Equal(t, "season", b.Values[2].ValueID)
assert.Equal(t, "winter", b.Values[2].Value)
assert.Equal(t, "SUN", b.Values[3].ValueID)
assert.Equal(t, "FLOWER", b.Values[3].Value)
})
}
func TestGetResults(t *testing.T) {
t.Run("Run getResults", func(t *testing.T) {
b := testSetup(&ClMock{}, "ABIFNLDCSQPOVMXK4DNPBDRW2M")
err := b.getResults()
assert.NoError(t, err)
assert.Equal(t, 1, len(b.Tasks[0].Results))
assert.Equal(t, 2, len(b.Tasks[1].Results))
assert.Equal(t, "image/jpeg", b.Tasks[1].Results[0].Mimetype)
assert.Equal(t, "application/octet-stream", b.Tasks[1].Results[1].Mimetype)
_, err = b.GetResult("does_not_exist")
assert.Error(t, err)
r, err := b.GetResult("SAR_XML")
assert.Equal(t, "application/octet-stream", r.Mimetype)
assert.NoError(t, err)
})
}