lundi 1 mars 2021

How to initialise a `type` of slice of interface in Golang

I have described a new type of slice of interface and want to initialise its value.

type ISampleData interface {
     ...
}

type Samples []ISampleData

type SampleData struct {  // This struct implements interface `ISampleData`
    ...
}

My method returns Samples type. I am writing unit test cases where I want to initialise a Samples value to compare (reflect.DeepEqual) with the value returned from the method. How to do it?

What I've tried: I initialised a variable with []SampleData values (Samples is a slice of ISampleData, which is implemented by SampleData), but reflection doesn't show them as equals.





Aucun commentaire:

Enregistrer un commentaire