Go: build error when compiling unit tests (I'm trying to mock influxdb types)

一世执手 提交于 2021-01-29 08:00:50

问题


I'm just starting with go language. My mini-project successfully reads data from InfluxDB. Problem: when I import my package (which uses InfluxDB) into my unit test package, the build fails.

"Production" code:

package data

import client "github.com/influxdata/influxdb1-client/v2"

func FunctionToTest() {}

// To make import necessary, unused for now
func createClient() (client.Client, error) {
    return client.NewHTTPClient(client.HTTPConfig{Addr: addr})
}

Unit test:

package data_test

import (
    "../data"
    "testing"
)

func TestSandBox(t *testing.T) {
    data.FunctionToTest()
}

I expected this to compile/run but:

# crypto/x509
In file included from /usr/local/go/src/crypto/x509/root_cgo_darwin.go:17:
In file included from /System/Library/Frameworks/Security.framework/Headers/Security.h:31:
/System/Library/Frameworks/Security.framework/Headers/SecItem.h:452:36: error: expected a version of the form 'major[.minor[.subminor]]'
    API_AVAILABLE(macos(10.7), ios(NA));
                                   ^
/usr/include/os/availability.h:61:181: note: expanded from macro 'API_AVAILABLE'
    #define API_AVAILABLE(...) __API_AVAILABLE_GET_MACRO(__VA_ARGS__,__API_AVAILABLE6, __API_AVAILABLE5, __API_AVAILABLE4, __API_AVAILABLE3, __API_AVAILABLE2, __API_AVAILABLE1, 0)(__VA_ARGS__)
                                                                                                                                                                                    ^
/usr/include/AvailabilityInternal.h:52025:54: note: expanded from macro '__API_AVAILABLE2'
    #define __API_AVAILABLE2(x,y) __API_A(x) __API_A(y)
                                                     ^
/usr/include/AvailabilityInternal.h:52023:79: note: expanded from macro '__API_A'
    #define __API_A(x) __attribute__((availability(__API_AVAILABLE_PLATFORM_##x)))
                                                                              ^
/usr/include/AvailabilityInternal.h:52018:60: note: expanded from macro '__API_AVAILABLE_PLATFORM_ios'
    #define __API_AVAILABLE_PLATFORM_ios(x) ios,introduced=x
                                                           ^

go env output:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/johndoe/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/johndoe/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4q/0yrdcxfd69x4mwzhvmwqg_gh0000gn/T/go-build020613348=/tmp/go-build -gno-record-gcc-switches -fno-common"

Thanks for any help or suggestion.

来源:https://stackoverflow.com/questions/57498765/go-build-error-when-compiling-unit-tests-im-trying-to-mock-influxdb-types

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!