返回接口的测试功能

I'm having difficulty writing test for the case below.

I'm able to write test for "helper" with a mock object that only implements the functions that used by myself.

How do I write test code for the function 'new' using a mock object without mocking functions C(), D()?

It could be that the other package is written poorly that it should not return an Interface but rather the actual struct?

package main

import (
    "fmt"
)

func main() {
    New()
}

func New() {
    new(NewFromEnvironment)
}

type newTopology func()(Interface,error)

// new is non-exposed simply used for testing purpose.
func new(newTopology newTopology) {
  t,_ :=  newTopology()
  helper(t)
}

// I need to call only A and B
type topologyInterface interface {
    A() string
    B() string
}

func helper(topology topologyInterface) {
    s1 := topology.A()
    s2 := topology.B()
    fmt.Println(s1 + "," + s2)
}

// Below are from other package named "topology".
// I have no control to the code below.

type Interface interface {
    A() string
    B() string
    C() string
    D() string
    //... more
}

func NewFromEnvironment() (Interface, error) {
    return P{}, nil
}

type P struct{}

func (p P) A() string {
    return "A"
}

func (p P) B() string {
    return "B"
}

func (p P) C() string {
    return "C"
}

func (p P) D() string {
    return "D"
}

// more...

You can try creating a struct MockP which embeds P. Then MockP inherits all the methods of P, but you can shadow A() and B() with your own mock implementations. Here's an example:

package main

import (
    "fmt"
)

type Interface interface {
    A()
    B()
}

type P struct {
}

func (p P) A() {
    fmt.Println("A")
}


func (p P) B() {
    fmt.Println("B")
}

type MockP struct {
    P
}

// Shadow P's B() method
func (p MockP) B() {
    fmt.Println("Mock B")
}

func main() {
    var p Interface = MockP{}
    p.A()
    p.B()
}

Output:

A
Mock B