error in testcode

49 views
Skip to first unread message

Dr. Lincy Jim

unread,
Mar 29, 2021, 2:40:27 AM3/29/21
to golang-nuts
Hi all,

I have included the following lines of code
if b.ConsentProvided {
        var t string
        if bl.Status != StatusExpired && bl.Status != StatusCancelled {

            t = fmt.Sprintf("Consent to share information by %s", bl.RequestedBy) //lchangetest1
            if len(bl.RequestedBy) == 0 {
                t = "Consent to share information"

            }

        } else {
            t = "Consent to share information"
        }
how to write a test code for this 

I wrote
func TestProvisionhistory(t *testing.T) {
bl := BookingListing {
Status:            "Expired"}
var thh = b1.provisionHistory(t.Booking)

    if thh.Status != StatusExpired && thh.Status != StatusCancelled {
        t.Error("Fail")
    } else {
        t.Error("True")
    }
Booking listing is a struct

What am  I doing wrong?

thanking in advance

Brian Candler

unread,
Mar 29, 2021, 3:19:51 AM3/29/21
to golang-nuts
Can you make a complete, runnable example which demonstrates the problem, on play.golang.org, and post the link here?

Dr. Lincy Jim

unread,
Mar 29, 2021, 4:01:09 AM3/29/21
to Brian Candler, golang-nuts
I did

func TestProvisionhistory(t *testing.T) {

type fields struct {

        Status            Status

        Type              BookingType

        Updated           time.Time

        History           []BookingHistory

        

    }

    type args struct {

        b *Booking

    }

    tests := []struct {

        name   string

        fields fields

        args   args

    
for _, tt := range tests {

        t.Run(tt.name, func(t *testing.T) {

            bl := &BookingListing{
Status:            tt.fields.Status}
if bl.Status == StatusExpired && bl.Status != StatusCancelled {

                t.Error("expecting status of bookinglisting to be active")

            }

 

            bl.provisionHistory(tt.args.b)

        })

    }

}

now i am getting  ok in the terminal

is this all that is required from writing If b1.status test code

Thanks and Regards/-
Dr.Lincy Elizebeth Jim,



On Mon, Mar 29, 2021 at 6:20 PM Brian Candler <b.ca...@pobox.com> wrote:
Can you make a complete, runnable example which demonstrates the problem, on play.golang.org, and post the link here?

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/gxtF2eEzjLI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/dabb8639-fec8-4c28-bab2-9d4484dd7716n%40googlegroups.com.

Brian Candler

unread,
Mar 29, 2021, 5:11:16 AM3/29/21
to golang-nuts
Sorry, but that is not a complete, self-contained piece of code that I can run.
Reply all
Reply to author
Forward
0 new messages