go - 忽略 librd kafka 中的测试

标签 go apache-kafka dockerfile librdkafka

我的golang项目依赖librd kafka

当我尝试从我的 jenkin 运行 go vet ./...go test ./... 时,出现以下错误。我相信这是因为我正在运行 ./... 但即使我不得不忽略 vendor ,我也不确定应该是什么我尝试了 go test $( go list ./... | grep -v/vendor/librdkafka) 但它没有帮助。

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/confluent-kafka-go.v1@v1.4.2/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mock_cgrp_member_add':

(.text+0x8e5): undefined reference to `__strndup'

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/confluent-kafka-go.v1@v1.4.2/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mock_cgrp_get':

(.text+0xd1e): undefined reference to `__strndup'

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: (.text+0xd46): undefined reference to `__strndup'

/usr/lib/gcc/x86_64-alpine-linux-musl/9.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/gopkg.in/confluentinc/confluent-kafka-go.v1@v1.4.2/kafka/librdkafka/librdkafka_glibc_linux.a(rdkafka_mock_cgrp.o): in function `rd_kafka_mcgrp_rebalance_timer_cb':

(.text+0x13dd): undefined reference to `__strndup'

我想知道如何在测试我的项目时解决 gcc 错误

我的 Dockerfile :

FROM golang:1.14-alpine AS builder

WORKDIR /src
ENV CGO_ENABLED=0
RUN apk add --no-cache git make
RUN go get \
        github.com/AlekSi/gocov-xml \
        github.com/axw/gocov \
        github.com/tebeka/go2xunit \
        github.com/wadey/gocovmerge



COPY go.mod go.sum ./
RUN  go get -d -v ./...
RUN  go mod download

COPY . .

FROM test AS builder
ENV CGO_ENABLED=1
#this config is for lib rd kafka setup
RUN set -ex &&\
    apk add --no-progress --no-cache \
      gcc \
      musl-dev

WORKDIR /src

RUN go install -tags musl ./...

我的 jenkins 文件片段

    stage("Test") {
        agent {
            dockerfile {
                label 'docker'
                additionalBuildArgs '--target test'
                args '-v test:/src/test'
                reuseNode true
            }
        }

        steps {
            parallel(
                    'Unit Test': {
                        sh "make ${makeArgs} test/unit-test"
                    },
                    Coverage: {
                        sh "make ${makeArgs} test/coverage"
                    },
                    Vet: {
                        sh "make ${makeArgs} test/vet"
                    }
            )
        }
        post {
            always {
                junit 'test/*xml'
                publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'test', reportFiles: 'coverage.html', reportName: 'Code Coverage Report'])
                sh "make ${makeArgs} clean"
            }
        }
    }

最佳答案

我只需要运行它-tags musl

go vet -tags musl ./...

关于go - 忽略 librd kafka 中的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63583633/

相关文章:

json - 将 colly 包输出文本添加到 golang 中的映射

docker - $GOPATH/go.mod 存在,但在构建 docker 容器时不应该存在,但如果我手动运行命令就可以工作

java - Kafka不使用偏移量而是通过记录的字段从主题中删除记录

docker - 在 dockerfile 中安装包

go - Go 中的方法前缀

Go lang func参数类型

java - 如何让Kafka消费者从特定主题分区读取Spring Boot

http - 为什么kafka不用http?

python - 在 Docker 中运行多个 python 进程

在生产中部署 Angular 应用程序 - 获取不同的 cli 版本