github.com/Axway/agent-sdk@v1.1.101/pkg/apic/provisioning/requeststatus_test.go (about) 1 package provisioning_test 2 3 import ( 4 "testing" 5 6 v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1" 7 "github.com/Axway/agent-sdk/pkg/apic/provisioning" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestRequestStatusBuilder(t *testing.T) { 12 tests := []struct { 13 name string 14 success bool 15 message string 16 propKey string 17 propVal string 18 prevReasons []v1.ResourceStatusReason 19 props map[string]string 20 }{ 21 { 22 name: "Build Success Status", 23 message: "message", 24 propKey: "key", 25 propVal: "val", 26 success: true, 27 }, 28 { 29 name: "Build Failed Status", 30 message: "message", 31 propKey: "key", 32 propVal: "val", 33 props: map[string]string{"a": "b"}, 34 prevReasons: []v1.ResourceStatusReason{ 35 { 36 Type: "Error", 37 Detail: "detail", 38 Meta: map[string]interface{}{ 39 "action": "CredentialExpired", 40 }, 41 }, 42 }, 43 success: false, 44 }, 45 } 46 for _, tt := range tests { 47 t.Run(tt.name, func(t *testing.T) { 48 builder := provisioning.NewRequestStatusBuilder().SetCurrentStatusReasons(tt.prevReasons).SetMessage("").AddProperty(tt.propKey, tt.propVal) 49 if tt.props != nil { 50 builder.SetProperties(tt.props) 51 } 52 53 var req provisioning.RequestStatus 54 if tt.success { 55 req = builder.Success() 56 } else { 57 req = builder.Failed() 58 } 59 60 assert.EqualValues(t, tt.prevReasons, req.GetReasons()) 61 if tt.props != nil { 62 assert.EqualValues(t, tt.props, req.GetProperties()) 63 } else { 64 assert.EqualValues(t, map[string]string{tt.propKey: tt.propVal}, req.GetProperties()) 65 } 66 assert.NotNil(t, req) 67 68 newReq := provisioning.NewStatusReason(req) 69 assert.EqualValues(t, len(tt.prevReasons)+1, len(newReq.Reasons)) 70 assert.NotNil(t, req) 71 }) 72 } 73 }