Cannot initialize []interface{} as function parameter

Viewed 53

I'm writing tests for Go application, my tested function is like this:

func CalculateProblem(events []interface{}){}

I'm trying to create this parameter(events) but without success. Below is my function:

func TestCalculateProblem(t *testing.T) {

    events := [][4] uint64 {{1,1,1,1}, {1,1,1,1}, {1,1,1,1}}

    CalculateProblem(events)
}

I receive the following compile error: cannot use events (variable of type [][4]uint64) as []interface{} value in argument to CalculateProblem

1 Answers

You can do something like this.

func TestCalculateProblem(t *testing.T) {
    eventA := [4]uint64{1, 1, 1, 1}
    eventB := [4]uint64{1, 1, 1, 1}    
    CalculateProblem([]interface{}{eventA, eventB})
}
Related