jeudi 23 novembre 2017

How can I test that the return value from a function in go is a pointer to a type?

I have highlighted in the test case where I expect something should go. Ideally I would like to test that i is an instance of WHAT_SHOULD_I_PUT_HERE

main.go

package main

import "fmt"

type SomeType struct {
    thingThatNeedsSetup struct{}
}

func Create() *SomeType {
    return &SomeType{}
}

func main() {
    a := Create()
    fmt.Println(a.thingThatNeedsSetup)
}

main_test.go

package main

import (
    "testing"
)

func TestCreate(t *testing.T) {

    i := Create()

    if i != WHAT_SHOULD_I_PUT_HERE {
        t.Error()
    }   
}

Aucun commentaire:

Enregistrer un commentaire